From 312d21d8635065c14d392b4e5469e7abc03f2bde Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 9 Jan 2019 11:35:14 -0500 Subject: Update docs & tests to reflect that unassigned OLD/NEW are now NULL. For a long time, plpgsql has allowed trigger functions to parse references to OLD and NEW even if the current trigger event type didn't assign a value to one or the other variable; but actually executing such a reference would fail. The v11 changes to use "expanded records" for DTYPE_REC variables changed the behavior so that the unassigned variable now reads as a null composite value. While this behavioral change was more or less unintentional, it seems that leaving it like this is better than adding code and complexity to be bug-compatible with the old way. The change doesn't break any code that worked before, and it eliminates a gotcha that often required extra code to work around. Hence, update the docs to say that these variables are "null" not "unassigned" when not relevant to the event type. And add a regression test covering the behavior, so that we'll notice if we ever break it again. Per report from Kristjan Tammekivi. Discussion: https://postgr.es/m/CAABK7uL-uC9ZxKBXzo_68pKt7cECfNRv+c35CXZpjq6jCAzYYA@mail.gmail.com --- doc/src/sgml/plpgsql.sgml | 4 ++-- doc/src/sgml/release-11.sgml | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index c9452cd4f94..c4f055eb560 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -3857,7 +3857,7 @@ ASSERT condition , Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level - triggers. This variable is unassigned in statement-level triggers + triggers. This variable is null in statement-level triggers and for DELETE operations. @@ -3869,7 +3869,7 @@ ASSERT condition , Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in row-level - triggers. This variable is unassigned in statement-level triggers + triggers. This variable is null in statement-level triggers and for INSERT operations. diff --git a/doc/src/sgml/release-11.sgml b/doc/src/sgml/release-11.sgml index f35b0d8cc93..b129d32264c 100644 --- a/doc/src/sgml/release-11.sgml +++ b/doc/src/sgml/release-11.sgml @@ -1033,6 +1033,23 @@ Branch: REL9_3_STABLE [84261eb10] 2018-10-19 17:02:26 -0400 + + + + + In PL/pgSQL trigger functions, the OLD + and NEW variables now read as NULL when not + assigned (Tom Lane) + + + + Previously, references to these variables could be parsed but not + executed. + + + @@ -2574,7 +2591,6 @@ same commits as above -- cgit v1.2.3