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

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: "Cast" SRF returning record to a table type?
Дата
Msg-id CAKFQuwZTEBBoK_AgeD3oCUbAU11RH4kUiWcTdtt7pa1OogQ-HA@mail.gmail.com
обсуждение исходный текст
Ответ на "Cast" SRF returning record to a table type?  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Ответы Re: "Cast" SRF returning record to a table type?  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Список pgsql-general
On Friday, April 17, 2015, Jim Nasby <Jim.Nasby@bluetreble.com> wrote:
I'm working on a function that will return a set of test data, for unit testing database stuff. It does a few things, but ultimately returns SETOF record that's essentially:

RETURN QUERY EXECUTE 'SELECT * FROM ' || table_name;

Because it's always going to return a real relation, I'd like to be able to the equivalent of:

SELECT ... FROM my_function( 'some_table' )::some_table;

Unfortunately this means "cast the existing type to some_table" and "record" is not a valid type in this context.
 

Is there any trick that would allow that to work? I know that instead of 'SELECT * ...' I can do 'SELECT row(t.*) FROM ' || table_name || ' AS t' and then do

SELECT ... FROM my_function( 'some_table' ) AS data( d some_table )

but I'm hoping to avoid the extra level of indirection.

 
Haven't explored this specific code in depth...but which part - the function alias or the select row(t.*)?  They seem to be independent concerns.

David J.

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

Предыдущее
От: Jim Nasby
Дата:
Сообщение: "Cast" SRF returning record to a table type?
Следующее
От: Jim Nasby
Дата:
Сообщение: Re: Waiting on ExclusiveLock on extension