Unix Technical Forum

OUT parameters in PL/Java

This is a discussion on OUT parameters in PL/Java within the pgsql Hackers forums, part of the PostgreSQL category; --> I've read about changes in CVS head needed to accomodate OUT parameters. I tried to compile PL/Java and it ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 04:23 AM
Thomas Hallgren
 
Posts: n/a
Default OUT parameters in PL/Java

I've read about changes in CVS head needed to accomodate OUT parameters.
I tried to compile PL/Java and it fails (of course). Is there any brief
text somewhere that highligts the changes that where made and explains
how the new stuff works? It's hard and somewhat time consuming to try to
deduct everything just by looking at the code in pl/pgsql.

Regards,
Thomas Hallgren


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 04:23 AM
Tom Lane
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Thomas Hallgren <thhal@mailblocks.com> writes:
> I've read about changes in CVS head needed to accomodate OUT parameters.
> I tried to compile PL/Java and it fails (of course). Is there any brief
> text somewhere that highligts the changes that where made and explains
> how the new stuff works? It's hard and somewhat time consuming to try to
> deduct everything just by looking at the code in pl/pgsql.


Could you give more details about what problem you are having? Simply
recompiling an existing PL shouldn't fail (of course, it wouldn't know
about OUT parameters either).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 04:23 AM
Thomas Hallgren
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Tom Lane wrote:
> Thomas Hallgren <thhal@mailblocks.com> writes:
>
>>I've read about changes in CVS head needed to accomodate OUT parameters.
>>I tried to compile PL/Java and it fails (of course). Is there any brief
>>text somewhere that highligts the changes that where made and explains
>>how the new stuff works? It's hard and somewhat time consuming to try to
>>deduct everything just by looking at the code in pl/pgsql.

>
>
> Could you give more details about what problem you are having? Simply
> recompiling an existing PL shouldn't fail (of course, it wouldn't know
> about OUT parameters either).
>

My compile failure was due to the change of proargtypes from Oid* to an
oidvector. I initially thought that had something to do with OUT parameters.

Some diffs on plperl helped me a bit. I found the new
get_call_result_type() function. I've made some assumptions that I would
like to verify the correctness of:

- I assume that by using the get_call_result_type() PL/Java will not
need any specific handling of functions returning OUT parameters since
they are similar to functions returning a complex type.

- The TupleDesc returned by the get_call_result_type() is not always
reachable using an Oid. I.e. I cannot use TypeGetTupleDesc(oid, NIL)
with the Form_pg_proc.prorettype of my function as the first argument.

- The Form_pg_proc.pronargs denotes the number of IN parameters, i.e.
its safe to access proargtypes.values[idx] with an idx ranging from 0 to
pronargs - 1.

Regards,
Thomas Hallgren


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 04:23 AM
Tom Lane
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Thomas Hallgren <thhal@mailblocks.com> writes:
> My compile failure was due to the change of proargtypes from Oid* to an
> oidvector. I initially thought that had something to do with OUT parameters.


No, not directly. The diffs needed for that are pretty simple though.

> - I assume that by using the get_call_result_type() PL/Java will not
> need any specific handling of functions returning OUT parameters since
> they are similar to functions returning a complex type.


If you use that, it will look just the same as the existing situation
where you are declared to return RECORD and someone calls you with
a column name/type list in FROM. Whether you want any additional
smarts is up to you.

> - The TupleDesc returned by the get_call_result_type() is not always
> reachable using an Oid. I.e. I cannot use TypeGetTupleDesc(oid, NIL)
> with the Form_pg_proc.prorettype of my function as the first argument.


That was true before for the RECORD case.

> - The Form_pg_proc.pronargs denotes the number of IN parameters, i.e.
> its safe to access proargtypes.values[idx] with an idx ranging from 0 to
> pronargs - 1.


Right, pronargs/proargtypes still denote the call signature and thus
only count IN (and INOUT) parameters.

One thing to be a bit wary of is that when OUT arguments are present,
subscripts in proargnames line up with proallargtypes not proargtypes.
I dunno if you are using proargnames at all, but if you are, the code
is likely to misbehave if it doesn't know that.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 04:23 AM
Thomas Hallgren
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Tom Lane wrote:
> If you use that, it will look just the same as the existing situation
> where you are declared to return RECORD and someone calls you with
> a column name/type list in FROM. Whether you want any additional
> smarts is up to you.
>
>
>>- The TupleDesc returned by the get_call_result_type() is not always
>>reachable using an Oid. I.e. I cannot use TypeGetTupleDesc(oid, NIL)
>>with the Form_pg_proc.prorettype of my function as the first argument.

>
>
> That was true before for the RECORD case.
>

PL/Java will not handle the RECORD case gracefully at present I'm
afraid. The 8.0 compatible version will need some improvements. How is
the TupleDesc obtained in case of RECORD in 8.0.x? Is it the same in 7.4?

>
>>- The Form_pg_proc.pronargs denotes the number of IN parameters, i.e.
>>its safe to access proargtypes.values[idx] with an idx ranging from 0 to
>>pronargs - 1.

>
>
> Right, pronargs/proargtypes still denote the call signature and thus
> only count IN (and INOUT) parameters.
>
> One thing to be a bit wary of is that when OUT arguments are present,
> subscripts in proargnames line up with proallargtypes not proargtypes.
> I dunno if you are using proargnames at all, but if you are, the code
> is likely to misbehave if it doesn't know that.
>

Thanks a lot. Now I know how to go about this. Seems pretty stright
forward. Nice work!

Regards,
Thomas Hallgren

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 04:23 AM
Tom Lane
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Thomas Hallgren <thhal@mailblocks.com> writes:
> PL/Java will not handle the RECORD case gracefully at present I'm
> afraid. The 8.0 compatible version will need some improvements. How is
> the TupleDesc obtained in case of RECORD in 8.0.x? Is it the same in 7.4?


In 8.0 and before I think you have to look in fcinfo->resultinfo to see
if an expectedDesc is supplied via a ReturnSetInfo. get_call_result_type()
handles that case along with the OUT-parameters case and the returns-a-
named-composite-type case, so it makes things a little easier and more
consistent.

You could do worse than to back-port get_call_result_type() into your
older branches and just leave out the code for the OUT parameter case.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 04:24 AM
Thomas Hallgren
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Tom Lane wrote:

>You could do worse than to back-port get_call_result_type() into your
>older branches and just leave out the code for the OUT parameter case.
>
>

Great advice! I went ahead and did just that. Now PL/Java handles
IN/INOUT/OUT parameters correctly with 8.1 and it handles functions
returning SETOF RECORD in all versions. The only thing that doesn't work
right now is a function that returns RECORD (not SETOF) since the rsinfo
in this case is NULL. Can you shed some light on that?

Regards,
Thomas Hallgren


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-11-2008, 04:24 AM
Tom Lane
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Thomas Hallgren <thhal@mailblocks.com> writes:
> ... The only thing that doesn't work
> right now is a function that returns RECORD (not SETOF) since the rsinfo
> in this case is NULL. Can you shed some light on that?


What's the test case exactly?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-11-2008, 04:24 AM
Thomas Hallgren
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Tom Lane wrote:

>Thomas Hallgren <thhal@mailblocks.com> writes:
>
>
>>... The only thing that doesn't work
>>right now is a function that returns RECORD (not SETOF) since the rsinfo
>>in this case is NULL. Can you shed some light on that?
>>
>>

>
>What's the test case exactly?
>
>
>

thhal=# create function javatest.recordExample(int, int) returns record
as 'org.postgresql.pljava.example.ComplexReturn.compl exReturn' immutable
language java;
CREATE FUNCTION
thhal=# select * from javatest.recordExample(3, 4) as (foo int, bar int,
baz timestamptz);
ERROR: could not determine row description for function returning record

(the error occurs since I make an attempt to fetch by Oid when the
TupleDesc is NULL. Oid in this case is RECORDOID).

Regards,
Thomas Hallgren


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-11-2008, 04:24 AM
Tom Lane
 
Posts: n/a
Default Re: OUT parameters in PL/Java

Thomas Hallgren <thhal@mailblocks.com> writes:
> thhal=# create function javatest.recordExample(int, int) returns record
> as 'org.postgresql.pljava.example.ComplexReturn.compl exReturn' immutable
> language java;
> CREATE FUNCTION
> thhal=# select * from javatest.recordExample(3, 4) as (foo int, bar int,
> baz timestamptz);
> ERROR: could not determine row description for function returning record


Hmm. I think this is not your bug. Is the call coming from
evaluate_function in clauses.c? We need to either prevent that from
pre-evaluating a function returning RECORD, or fix it so it can pass
the expected tuple descriptor ... probably the former :-(

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:28 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com