Re: "Cast" SRF returning record to a table type?

Поиск
Список
Период
Сортировка
От Jim Nasby
Тема Re: "Cast" SRF returning record to a table type?
Дата
Msg-id 5532DCA5.40407@BlueTreble.com
обсуждение исходный текст
Ответ на Re: "Cast" SRF returning record to a table type?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: "Cast" SRF returning record to a table type?  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
On 4/18/15 12:47 AM, David G. Johnston wrote:
> If you could find a way to pass a value of type some_table into the
> function - instead of the name/text 'some_table‘ - you could  possibly
> use polymorphic pseudotypes...just imagining here...

Oh, I didn't think about that. Maybe I'll try it.

What I ended up with is this:

CREATE FUNCTION ... (
) RETURNS SETOF text ...
...
RETURN QUERY EXECUTE format(
     'SELECT row(t.*)::text FROM %I.%I AS t'
     , ...
);

So the function is getting a record and casting it to text. To call the
function you have to...

SELECT (function(...))::name_of_table).*

that gives you the same output as if you'd selected directly from the table.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com


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

Предыдущее
От: John R Pierce
Дата:
Сообщение: Re: function to send email with query results
Следующее
От: Jim Nasby
Дата:
Сообщение: Re: ORDER BY for jsonb