why can't plpgsql return a row-expression?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: why can't plpgsql return a row-expression?
Date: 2012-10-08 14:42:27
Message-ID: CA+TgmoZKsw_13+zBqO3QmncK=kp+7-sWuv6NsMr7Z2K_wMW52Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

PL/pgsql seems to have a strange restriction regarding "RETURN".
Normally, you can write "RETURN <expression>". But if the function
returns a row type, then you can only write "RETURN variable" or
"RETURN NULL".

rhaas=# create type xyz as (a int, b int);
CREATE TYPE
rhaas=# select row(1,2)::xyz;
row
-------
(1,2)
(1 row)

rhaas=# create or replace function return_xyz() returns xyz as $$
rhaas$# begin
rhaas$# return row(1,2)::xyz;
rhaas$# end$$ language plpgsql;
ERROR: RETURN must specify a record or row variable in function returning row
LINE 3: return row(1,2)::xyz;
^

Off the top of my head, I can't think of any reason for this
restriction, nor can I find any code comments or anything in the
commit log which explains the reason for it. Does anyone know why we
don't allow this?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2012-10-08 14:53:03 Re: Improving psql \ds
Previous Message Amit Kapila 2012-10-08 14:42:23 Re: BUG #7534: walreceiver takes long time to detect n/w breakdown