Re: how to return more than 1 arg with a function ? - Mailing list pgsql-general

From Richard Huxton
Subject Re: how to return more than 1 arg with a function ?
Date
Msg-id 3A8E64F8.7345C5CA@archonet.com
Whole thread Raw
In response to how to return more than 1 arg with a function ?  (Feite Brekeveld <feite.brekeveld@osiris-it.nl>)
Responses Re: how to return more than 1 arg with a function ?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Feite Brekeveld wrote:
>
> I want to return mre than 1 arg
>
> create function func(varchar)
> --> returns var1, var2 ....
> as '
> ...
> '
> language 'sql';
>
> How to deal with the return : The manual says to use SETOF can't figure
> out how that works no examples are given.

Not quite right. SETOF returns many items so you could have:

create function list_ids() returns setof int4 as 'select id from foo;'
language 'sql';

select list_ids();

list_id
-------
1
2
7
12

You can also return a tuple like:

create function whole_row() returns foo as ...

But - that can only be used to feed into another function, not in a
"raw" select statement.

HTH

- Richard Huxton

pgsql-general by date:

Previous
From: Paul M Foster
Date:
Subject: Re: Re: PostgreSQL vs Oracle vs DB2 vs MySQL - Which should I use?
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Case insensitive selects?