Joshua D. Drake wrote: > But something like this fails: > > CREATE OR REPLACE FUNCTION test_multiple () RETURNS SETOF text AS > 'SELECT ''a'', ''b''' LANGUAGE 'SQL'; > ERROR: function declared to return text returns multiple columns in > final SELECT > > What are we missing? Try: CREATE OR REPLACE FUNCTION test_1 () RETURNS SETOF record AS 'SELECT ''a''::text, ''b''::text' LANGUAGE 'SQL'; regression=# SELECT * FROM test_1() AS t(f1 text, f2 text); f1 | f2 ----+---- a | b (1 row) or: CREATE TYPE mytype AS (f1 int, f2 text); CREATE OR REPLACE FUNCTION test_2 () RETURNS SETOF mytype AS 'SELECT 1::int, ''b''::text' LANGUAGE 'SQL'; regression=# SELECT * FROM test_2(); f1 | f2 ----+---- 1 | b (1 row) See the info scattered amongst: http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/sql-select.html http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/sql-createtype.html http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/xfunc-tablefunctions.html http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/xfunc-sql.html http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/xfunc-c.html http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/plpgsql-control-structures.html (and maybe some others) HTH, Joe
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных