Re: Allow SQL/plpgsql functions to accept record - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Allow SQL/plpgsql functions to accept record
Date
Msg-id 9863.1429998609@sss.pgh.pa.us
Whole thread Raw
In response to Re: Allow SQL/plpgsql functions to accept record  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Allow SQL/plpgsql functions to accept record
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Wed, Apr 22, 2015 at 6:12 PM, Jim Nasby <Jim.Nasby@bluetreble.com> wrote:
>> As for allowing SQL and plpgsql functions to accept a record, I think our
>> JSON functionality just provided plenty of reason we should allow accepting
>> them, even if you can't do much with it: you *can* hand it to row_to_json(),
>> which does allow you to do something useful with it. So it seems reasonable
>> to me that we should at least accept it as a function argument.

> I agree that that would be useful.  I think the problem with an
> expression like rowvar.something is that PL/pgsql cannot infer the
> type of the result, and nothing else works without that.  I doubt that
> it's practical to lift that restriction.

Well, we already support local variables of type RECORD in plpgsql, so
it's not immediately clear to me that function arguments would be much
worse.  There are a lot of deficiencies with the RECORD-local-variable
implementation: if you try to change the actual RECORD type from one call
to the next you'll probably have problems.  But it seems like we could
avoid that for function arguments by treating RECORD as a polymorphic
argument type, and thereby generating a separate set of plan trees for
each actual record type passed to the function within a given session.
So in principle it ought to work better than the local-variable case does
today.

In short I suspect that Jim is right and this has more to do with a
shortage of round tuits than any fundamental problem.

Not sure about the SQL-function case.  That might be even easier because
functions.c doesn't try to cache plans across queries; or maybe not.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: PL/pgSQL, RAISE and error context
Next
From: Tom Lane
Date:
Subject: Re: Shouldn't CREATE TABLE LIKE copy the relhasoids property?