Re: a column definition list is required for functions returning "record" - Mailing list pgsql-general

From Tom Lane
Subject Re: a column definition list is required for functions returning "record"
Date
Msg-id 26964.1472470091@sss.pgh.pa.us
Whole thread Raw
In response to Re: a column definition list is required for functions returning "record"  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: a column definition list is required for functions returning "record"  (Merlin Moncure <mmoncure@gmail.com>)
Re: a column definition list is required for functions returning "record"  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
List pgsql-general
Pavel Stehule <pavel.stehule@gmail.com> writes:
> 2016-08-29 1:59 GMT+02:00 Jim Nasby <Jim.Nasby@bluetreble.com>:
>> It would be nice if there was a way to pass dynamically formed records
>> around, similar to how you can pass the results of row() around. Someone
>> else has actually be asking about this at https://github.com/decibel/pg_
>> lambda/issues/1.

> Probably there is a space to be PLpgSQL more flexible - but there are
> limits - PLpgSQL is black box for SQL engine, and when output is any record
> type, then SQL engine knows zero about returning data structure in
> preprocessing time.

Exactly.  You can pass anonymous record types around today, as long as you
don't do anything that requires knowing what their contents are, either in
the function or in the calling query:

regression=# create function foor(int,int) returns record language sql as $$ select row($1,$2); $$;
CREATE FUNCTION
regression=# select foor(23,45);
  foor
---------
 (23,45)
(1 row)

regression=# create function plr(int,int) returns record language plpgsql as $$begin return row($1,$2); end; $$;
CREATE FUNCTION
regression=# select plr(23,45);
   plr
---------
 (23,45)
(1 row)

What you can't do is, eg,

regression=# select * from plr(23,45);
ERROR:  a column definition list is required for functions returning "record"
LINE 1: select * from plr(23,45);
                      ^

because the parser has no basis on which to expand the "*".  The column
definition list is exactly a hack for telling it that.

            regards, tom lane


pgsql-general by date:

Previous
From: Alexander Farber
Date:
Subject: Re: a column definition list is required for functions returning "record"
Next
From: hubert depesz lubaczewski
Date:
Subject: Any work on better parallelization of pg_dump?