Re: Howto return values from a function - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Howto return values from a function
Date
Msg-id 20080515123608.GB25867@svana.org
Whole thread Raw
In response to Howto return values from a function  ("A B" <gentosaker@gmail.com>)
Responses Re: Howto return values from a function  ("A B" <gentosaker@gmail.com>)
Re: Howto return values from a function  ("A B" <gentosaker@gmail.com>)
List pgsql-general
On Thu, May 15, 2008 at 02:25:36PM +0200, A B wrote:
> I'm still trying to learn to write plpgsql functions, but I find the
> docs a little short on examples on how to return stuff from a
> function. I'm very grateful for any help on this.

What exactly about the documentation isn't clear?

http://www.postgresql.org/docs/8.3/static/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING

> CREATE FUNCTION foo() RETURNS ???? AS

> but what do I write instead of ????

Like the documentation says: SETOF sometype.

> I'm nto sure here, but It seems to mee that there are two other ways
> of doing case 2.

How you generate the results is up to you. when you have them you
either use RETURN NEXT or RETURN QUERY to return them to the caller.

> 3) In the third case, I want to create the values I return  by joining
> many values. Something like this
> CREATE FUNCTION foo() RETURNS ???? AS

You can always use out parameters if you feel better about it:

CREATE FUNCTION foo(col1 int4 OUT, col2 text OUT, ...) AS ...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

Attachment

pgsql-general by date:

Previous
From: John DeSoi
Date:
Subject: Re: problem with importing dbf file into postgresql using navicat on mac OS X
Next
From: "Semi Noob"
Date:
Subject: Re: Need for help!