Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: Returning R...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 15501 of 17437
Post > Topic >>

Re: Returning RECORD from PGSQL without custom type?

by mail@[EMAIL PROTECTED] (Ivan Sergio Borgonovo) May 10, 2008 at 06:52 PM

On Sat, 10 May 2008 02:36:50 -0500
"D. Dante Lorenso" <dante@[EMAIL PROTECTED]
> wrote:

> Instead of doing this:
> 
>    CREATE OR REPLACE FUNCTION "my_custom_func" (in_value bigint)
>    RETURNS SETOF record AS
>    $body$
>    ...
>    $body$
>    LANGUAGE 'plpgsql' VOLATILE;

What's the problem with the above?
You don't like to specify the returned type in each "caller"?

then

CREATE OR REPLACE FUNCTION "my_custom_func" (in_value bigint
  out ret1 int, out ret2 text, out ret3 float
)
  RETURNS SETOF record AS
$body$
declare
  row record;
begin
  for ...

    ret1:=row.col1;
    ret2:=row.col2;
    if(row.col3)<7 then
      ret3:=row.col3;
    else
      ret3:=0;
    end if;
....
$body$
LANGUAGE 'plpgsql' VOLATILE;

then you can call
select ret2 from my_custom_func(100) where ret1<12;

> I'd like to be able to do this:
> 
>    CREATE OR REPLACE FUNCTION "my_custom_func" (in_value bigint)
>    RETURNS SETOF (col1name BIGINT, col2name TEXT, ...) AS
>    $body$
>    ...
>    $body$
>    LANGUAGE 'plpgsql' VOLATILE;
> 

it looks similar to the above...

>     RETURN NEXT OUT;
> 
>     OUT.col1name := 12345;
>     RETURN NEXT OUT;
> 
>     SELECT 12345, 'sample'
>     INTO OUT.col1name, OUT.col2name;
>     RETURN NEXT OUT;

I'm not sure if you can...

> Does this feature request make sense to everyone?  It would make 
> programming set returning record functions a lot easier.

yeah it could be a nice shortcut to define types "locally".

Once you call "OUT" the type, you could avoid the ret1:=row.


-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 3 Posts in Topic:
Returning RECORD from PGSQL without custom type?
dante@[EMAIL PROTECTED]   2008-05-10 02:36:50 
Re: Returning RECORD from PGSQL without custom type?
pavel.stehule@[EMAIL PROT  2008-05-10 12:13:46 
Re: Returning RECORD from PGSQL without custom type?
mail@[EMAIL PROTECTED] (  2008-05-10 18:52:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 12:50:23 CST 2008.