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

From: Kristjan Tammekivi <kristjantammekivi(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Potentially undocumented behaviour change in Postgres 11 concerning OLD record in an after insert trigger
Date: 2019-01-04 10:45:42
Message-ID: CAABK7uL-uC9ZxKBXzo_68pKt7cECfNRv+c35CXZpjq6jCAzYYA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Hi,

I've noticed a change in the behaviour in triggers / hstores in Postgres
11.1 when compared to Postgres 10.5.
The following won't work on Postgres 10.5 but in Postgres 11.1 it works
just fine:

CREATE EXTENSION hstore;

CREATE TABLE _tmp_test1 (id serial PRIMARY KEY, val INTEGER);
CREATE TABLE _tmp_test1_changes (id INTEGER, changes HSTORE);

CREATE FUNCTION test1_trigger ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS
$BODY$
BEGIN
INSERT INTO _tmp_test1_changes (id, changes) VALUES (NEW.id, hstore(OLD) -
hstore(NEW));
RETURN NEW;
END
$BODY$;

CREATE TRIGGER table_update AFTER INSERT OR UPDATE ON _tmp_test1
FOR EACH ROW EXECUTE PROCEDURE test1_trigger();

INSERT INTO _tmp_test1 (val) VALUES (5);
ERROR: record "old" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: SQL statement "INSERT INTO _tmp_test1_changes (id, changes)
VALUES (NEW.id, hstore(OLD) - hstore(NEW))"
PL/pgSQL function test1_trigger() line 3 at SQL statement

I couldn't find anything about this in the release notes (
https://www.postgresql.org/docs/11/release-11.html) but maybe I just
didn't know what to look for.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Charles Clavadetscher 2019-01-04 10:56:22 RE: Potentially undocumented behaviour change in Postgres 11 concerning OLD record in an after insert trigger
Previous Message Andrew Gierth 2019-01-04 10:27:29 Re: Function `set_config` doesn't work in with query?

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2019-01-04 10:54:42 Re: minor fix in CancelVirtualTransaction
Previous Message Peter Eisentraut 2019-01-04 10:41:15 Re: [PATCH] Pass COPT and PROFILE to CXXFLAGS as well