SELECT FROM function returning record with arbirary number of columns

I am using a PostgreSQL database.

I have my plpgsql FUNCTION, which returns a single recordwith an arbitrary number of columns.
Due to this arbitrariness, I will need to use something like:

SELECT * FROM my_function(97)

But this does not work, as Postgres gives me the following error:

column list required for functions returning a record

But if I do this:

SELECT my_function(97)

I see the expected result, but encapsulated in a single column.

Is there a way to get the expected result as a set of columns according to the purpose of the function, and not a single column that encapsulates all of them?

+5
source share
5 answers

RETURNS record SETOF record ( no OUT) , PostgreSQL , .

, , . @Chris, , . :

SO . , . !

+5

:

  • REFCURSOR . , REFCURSORS, .

  • XML- .

  • OUT, RECORD ,

, , . , .

+2

(setof) FROM . .

:

SELECT
  (my_function).field1,
  (my_function).field2,
  (my_function).field3
FROM
(SELECT my_function(*) 
 FROM sometable) t
+1

" ", TABLE SETOF, SET , SELECT from.

, SETOF,

0

, , , ?

SELECT (my_function(97)).my_column
-1
source

All Articles