Understanding setof

Started by Robert Jamesabout 12 years ago3 messagesgeneral
Jump to latest
#1Robert James
srobertjames@gmail.com

I'm having trouble with setof returning functions

Let's say I have function x() returning setof integers. I want to do
SELECT x(), but only keep the values which meet a criteria. Something
like: SELECT x() as xval WHERE xval = 10.

How can I do that?

In general, is there a way to "unroll" a setof into a regular query?

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

In reply to: Robert James (#1)
Re: Understanding setof

On 04/04/2014 20:42, Robert James wrote:

I'm having trouble with setof returning functions

Let's say I have function x() returning setof integers. I want to do
SELECT x(), but only keep the values which meet a criteria. Something
like: SELECT x() as xval WHERE xval = 10.

How can I do that?

In general, is there a way to "unroll" a setof into a regular query?

if you mean that you want just a normal set of rows from the function, I
think you just do this:

select * from x() s(t) where t = 10;

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

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

#3Jeff Janes
jeff.janes@gmail.com
In reply to: Robert James (#1)
Re: Understanding setof

On Fri, Apr 4, 2014 at 12:42 PM, Robert James <srobertjames@gmail.com>wrote:

I'm having trouble with setof returning functions

Let's say I have function x() returning setof integers. I want to do
SELECT x(), but only keep the values which meet a criteria. Something
like: SELECT x() as xval WHERE xval = 10.

How can I do that?

In general, is there a way to "unroll" a setof into a regular query?

Just add a FROM:

select * from x() as xval where xval=10;

Cheers,

Jeff