Re: stored procedure: RETURNS record

Поиск
Список
Период
Сортировка
От Rob Marjot
Тема Re: stored procedure: RETURNS record
Дата
Msg-id 671e36b0909251140u225ad023vf26d62e5bc826153@mail.gmail.com
обсуждение исходный текст
Ответ на Re: stored procedure: RETURNS record  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Ответы Re: stored procedure: RETURNS record  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: stored procedure: RETURNS record  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
Still no luck... To clarify a bit, take this example:

CREATE OR REPLACE FUNCTION transpose()
  RETURNS record AS
$BODY$ DECLARE
   output RECORD;
 BEGIN
   SELECT * INTO output FROM (VALUES(1,2)) as tbl(first,second);
   RETURN output;

 END;$BODY$
  LANGUAGE 'plpgsql' STABLE
  COST 100;

Now, I expect to have 2 columns; named "first" and "second". However, like posted before, the flowing query:
SELECT * FROM deserialize();
produces only ONE column (in one row, as one would clearly expect from the function's defnition):
 deserialize
-----------
 (1,2)
(1 row)


Any thoughts on how to make sure multiple columns are returned; without specifying this in the function's prototype return clause?

Thanks,


Rob

2009/9/25 Alban Hertroys <dalroi@solfertje.student.utwente.nl>
On 25 Sep 2009, at 18:34, InterRob wrote:

Unfortunately, this results in ONE row, with ONE column. E.g.:

MYDB=# select * from (SELECT deserialize(kvp) FROM kvp) ss;
 deserialize
-----------
 (1,2)
(1 row)

I guess I am seeking to prototype the anonymous row layout in the above SQL statement?


I'm not entirely sure about the syntax in your case, but I think you're looking for:

MYDB=# select * from (SELECT deserialize(kvp) FROM kvp) ss (a int, b int);

If that doesn't work, it's based on how you normally select from a record-returning function, namely:
MYDB=# SELECT * FROM deserialize('some string') AS ss (a int, b int);

You may need to call it like this though:
MYDB=# select * from (SELECT (deserialize(kvp)).a, (deserialize(kvp)).b FROM kvp) ss (a int, b int);

In that case your function better not be volatile or it will be evaluated twice.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:968,4abd04cd11681949045486!




В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: lazy vacuum and AccessExclusiveLock
Следующее
От: Steve Crawford
Дата:
Сообщение: pg_restore ordering questions