Re: SETOF (was: Function example returning more then 1 - Mailing list pgsql-general

From Antti Haapala
Subject Re: SETOF (was: Function example returning more then 1
Date
Msg-id Pine.GSO.4.44.0302271617440.22197-100000@paju.oulu.fi
Whole thread Raw
In response to Re: SETOF (was: Function example returning more then 1  (Kolus Maximiliano <Kolus.maximiliano@bcr.com.ar>)
List pgsql-general
On Thu, 27 Feb 2003, Kolus Maximiliano wrote:

> > You can't return more than one return value from function, but that
> > value can be of composite type.For example :"setof text" or "setof record"
> > are such types.
>
> Can you use functions returning "setof"s as if they were "normal"
> selects?.
>
> I saw that setof takes a type or table as an argument. What if what
> i want to return is not in a table schema, can i do something like "setof
> (blah inet, blah2 varchar(256))"?



CREATE TYPE compfoo AS (f1 int, f2 text);

CREATE FUNCTION getfoo() RETURNS SETOF compfoo AS 'SELECT fooid, fooname
FROM foo' LANGUAGE SQL;

or use setof record if column types aren't fixed. But then you need to use
syntax like

SELECT *
 FROM dblink('dbname=template1', 'select proname, prosrc from pg_proc')
   AS t1(proname name, prosrc text)
 WHERE proname LIKE 'bytea%';

More info about table functions is available in PostgreSQL 7.3
Programmer's Guide II. Server Programming in chapter "9.7 Table Funtions".

http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=xfunc-tablefunctions.html

--
Antti Haapala


pgsql-general by date:

Previous
From: "Peter Gibbs"
Date:
Subject: Re: PGSQL function question
Next
From: Herbert Liechti
Date:
Subject: pg_restore in debian postgresql 7.3.2-3