Monday 12 September 2011

Retrieving multiple columns from a Postgres function

I recently came across a problem retrieving multiple columns in Postgres, turns out the function needs to be treated as a table.



test=# CREATE FUNCTION numbers(OUT INT, OUT INT, OUT INT) RETURNS SETOF RECORD AS $$ SELECT 1, 2, 3; $$ LANGUAGE 'sql';
CREATE FUNCTION
test=# SELECT numbers();
 numbers
---------
 (1,2,3)
(1 row)

test=# SELECT * FROM numbers();
 column1 | column2 | column3
---------+---------+---------
       1 |       2 |       3
(1 row)

No comments:

Post a Comment