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

Started by PG Bug reporting formover 7 years ago1 messagesbugs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 15456
Logged by: Sean Johnston
Email address: sean.johnston@edgeintelligence.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.