Re: Potentially undocumented behaviour change in Postgres 11 concerning OLD record in an after insert trigger

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Kristjan Tammekivi <kristjantammekivi(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Potentially undocumented behaviour change in Postgres 11 concerning OLD record in an after insert trigger
Date: 2019-01-04 16:47:47
Message-ID: CAFj8pRDYTyLBmUc=N-rsJvL29mSL=6Rhs-H0bH6SQCx5gE4hqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

pá 4. 1. 2019 v 17:44 odesílatel Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> napsal:

> Kristjan Tammekivi <kristjantammekivi(at)gmail(dot)com> writes:
> > I've noticed a change in the behaviour in triggers / hstores in Postgres
> > 11.1 when compared to Postgres 10.5.
> > [ reference to OLD in an insert trigger doesn't throw error anymore ]
>
> Hmm. This seems to be a side effect of the changes we (I) made in v11
> to rationalize the handling of NULL vs ROW(NULL,NULL,...) composite
> values in plpgsql. The "unassigned" trigger row variables are now
> acting as though they are plain NULL values. I'm not sure now whether
> I realized that this would happen --- it looks like there are not and
> were not any regression test cases that would throw an error for the
> disallowed-reference case, so it's quite possible that it just escaped
> notice.
>
> The old behavior was pretty darn squirrely; in particular it would let
> you parse but not execute a reference to "OLD.column", a behavior that
> could not occur for any other composite variable. Now that'll just
> return NULL. In a green field I don't think there'd be complaints
> about this behavior --- I know lots of people have spent considerable
> effort programming around the other behavior.
>
> While I haven't looked closely, I think duplicating the old behavior
> would require adding a special-purpose flag to plpgsql DTYPE_REC
> variables, which'd cost a little performance (extra error checks
> in very hot code paths) and possibly break compatibility with
> pldebugger, if there's been a v11 release of that.
>
> So I'm a bit inclined to accept this behavior change and adjust
> the documentation to say that OLD/NEW are "null" rather than
> "unassigned" when not relevant.
>

It is maybe unwanted effect, but it is not bad from my view. new behave is
consistent - a initial value of variables is just NULL

+1

Pavel

> Thoughts?
>
> regards, tom lane
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2019-01-04 16:53:19 Comparing dates in DDL
Previous Message Tom Lane 2019-01-04 16:44:23 Re: Potentially undocumented behaviour change in Postgres 11 concerning OLD record in an after insert trigger

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-01-04 17:26:18 Re: reducing the footprint of ScanKeyword (was Re: Large writable variables)
Previous Message Tom Lane 2019-01-04 16:44:23 Re: Potentially undocumented behaviour change in Postgres 11 concerning OLD record in an after insert trigger