Re: NEW.* and OLD.* inside trigger function don't seem to contain recently added columns

From: Janne Annala <janne(dot)annala(at)forenom(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: NEW.* and OLD.* inside trigger function don't seem to contain recently added columns
Date: 2024-03-25 08:15:02
Message-ID: PA6PR08MB10705EBE4238110979369606E8A362@PA6PR08MB10705.eurprd08.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)sss(dot)pgh(dot)pa(dot)us>
Sent: Saturday, 23 March 2024 2.41
To: Janne Annala <janne(dot)annala(at)forenom(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org <pgsql-bugs(at)lists(dot)postgresql(dot)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(at)sss(dot)pgh(dot)pa(dot)us(dot) Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Janne Annala <janne(dot)annala(at)forenom(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2024-03-25 10:09:11 BUG #18406: Connection issue after upgrading to postgres16
Previous Message PG Bug reporting form 2024-03-23 18:09:02 BUG #18405: flaw in dump of inherited/dropped constraints