BUG #15456: Trigger function using ROW(NEW.*) has wrong columns if table is modified during a session

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: sean(dot)johnston(at)edgeintelligence(dot)com
Subject: BUG #15456: Trigger function using ROW(NEW.*) has wrong columns if table is modified during a session
Date: 2018-10-24 12:26:53
Message-ID: 15456-ac99771a43cdd95e@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 15456
Logged by: Sean Johnston
Email address: sean(dot)johnston(at)edgeintelligence(dot)com
PostgreSQL version: 11.0
Operating system: Ubuntu 14.04
Description:

-- 1. create trigger function

create or replace function trig() returns trigger as $$
begin
if TG_OP = 'INSERT' then
raise notice 'INSERT: %', ROW(NEW.*);
end if;
return null;
end $$ language plpgsql;

-- 2. create table

drop table if exists t;
create table t (id integer) tablespace pg_default;

-- 3. create a trigger on the table for each row

create trigger do_trig
after insert or update or delete on t
for each row
execute procedure trig();

-- 4. insert a row

insert into t(id) values (1);

-- 5. add a column to the table

alter table t add val text;

-- 6. insert a new row referencing the new column

insert into t(id,val) values (2,'new');

------

Output from notices:
psql:1.sql:18: NOTICE: INSERT: (1)
psql:1.sql:22: NOTICE: INSERT: (2)

Expected output:
psql:1.sql:18: NOTICE: INSERT: (1)
psql:1.sql:22: NOTICE: INSERT: (2,new)

Note that if a new session is started before performing the second insert
then the expected output is produced.

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2018-10-24 13:01:16 Re: psql on Mac
Previous Message Ozan Kahramanogullari 2018-10-24 12:02:14 Re: psql on Mac