Re: NEW.* and OLD.* inside trigger function don't seem to contain recently added columns - Mailing list pgsql-bugs

From Janne Annala
Subject Re: NEW.* and OLD.* inside trigger function don't seem to contain recently added columns
Date
Msg-id PA6PR08MB10705EBE4238110979369606E8A362@PA6PR08MB10705.eurprd08.prod.outlook.com
Whole thread Raw
In response to Re: NEW.* and OLD.* inside trigger function don't seem to contain recently added columns  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Hey Tom,

Thank you for taking the time to look at the issue. It appears the ROW() notation was indeed unnecessary in this situation. I tried the methods you described, and they work perfectly.

I consider the primary issue solved. I assume your team will consider whether the original behaviour is considered a bug and if it's worth fixing or not.

Thanks again
Janne Annala

From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Saturday, 23 March 2024 2.41
To: Janne Annala <janne.annala@forenom.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: NEW.* and OLD.* inside trigger function don't seem to contain recently added columns
 
[You don't often get email from tgl@sss.pgh.pa.us. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Janne Annala <janne.annala@forenom.com> writes:
> Here's the minimum case to reproduce the issue:

> CREATE FUNCTION x()
>  RETURNS trigger
>  LANGUAGE plpgsql
> AS $function$
> BEGIN
>   IF ROW(NEW.*) IS DISTINCT FROM ROW(OLD.*) THEN

Try dropping the ROW() bit, that is just

   IF NEW.* IS DISTINCT FROM OLD.* THEN

or even

   IF NEW IS DISTINCT FROM OLD THEN

I think what is happening is that the ROW() notation is getting
expanded at parse time to

   ROW(NEW.id, NEW.old_column, NEW.updated)

and then there's no dependency on the original rowtype that would
lead to that expansion getting reconsidered.  Arguably that's a
bug, but it's not clear to me what the consequences of changing
that behavior would be.

                        regards, tom lane

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18405: flaw in dump of inherited/dropped constraints
Next
From: PG Bug reporting form
Date:
Subject: BUG #18406: Connection issue after upgrading to postgres16