Re: [GENERAL] Returning a RECORD, not SETOF RECORD
От | Tom Lane |
---|---|
Тема | Re: [GENERAL] Returning a RECORD, not SETOF RECORD |
Дата | |
Msg-id | 5830.1114785365@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: [GENERAL] Returning a RECORD, not SETOF RECORD (Thomas Hallgren <thhal@mailblocks.com>) |
Ответы |
Re: [GENERAL] Returning a RECORD, not SETOF RECORD
|
Список | pgsql-hackers |
Thomas Hallgren <thhal@mailblocks.com> writes: > Ideally I'd like to write something like this: > SELECT xyz(a, b) AS (x int, y int, z timestamptz) FROM abc; > but that yields a syntax error. While that's probably doable if anyone were really motivated, I'm not sure it's worth the trouble in view of the recent OUT-parameter improvements. IMHO most of the use cases for such a thing would be better served by declaring the function with OUT parameters. The AS-clause-column-list functionality was invented for functions where the result type is truly not known when the function is written, such as dblink. But it's pretty hard to believe that many people need to write such things. Your example can be done like this in CVS tip: regression=# create function xyz(int, int, out x int, out y int, out z timestamptz) as $$ select $1, $2, now() $$ languagesql; CREATE FUNCTION regression=# select xyz(unique1,unique2) from tenk1 limit 5; xyz ------------------------------------------(8800,0,"2005-04-29 10:26:37.738946-04")(1891,1,"2005-04-29 10:26:37.738946-04")(3420,2,"2005-04-2910:26:37.738946-04")(9850,3,"2005-04-29 10:26:37.738946-04")(7164,4,"2005-04-29 10:26:37.738946-04") (5 rows) Notice that this returns the record as a single column. In most cases you would probably wish that the record were burst into multiple columns, which you can do easily with regression=# select (xyz(unique1,unique2)).* from tenk1 limit 5; x | y | z ------+---+-------------------------------8800 | 0 | 2005-04-29 10:27:53.197948-041891 | 1 | 2005-04-29 10:27:53.197948-043420| 2 | 2005-04-29 10:27:53.197948-049850 | 3 | 2005-04-29 10:27:53.197948-047164 | 4 | 2005-04-29 10:27:53.197948-04 (5 rows) but AFAICS that is not amenable to having an AS plastered on it (unless the AS goes inside the parentheses, which'd be a really spectacular abuse of the syntax). regards, tom lane
В списке pgsql-hackers по дате отправления: