Re: Returning multiple columns with a function??

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: Returning multiple columns with a function??
Дата
Msg-id 3DFE7475.7060508@joeconway.com
обсуждение исходный текст
Ответ на Returning multiple columns with a function??  ("Joshua D. Drake" <jd@commandprompt.com>)
Список pgsql-general
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 по дате отправления:

Предыдущее
От: Hadley Willan
Дата:
Сообщение: Re: Changing a column's type
Следующее
От: "Magnus Naeslund(f)"
Дата:
Сообщение: Re: [HACKERS] following instructions GCC