pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: sean.johnston@edgeintelligence.com
Subject: BUG #15456: Trigger function using ROW(NEW.*) has wrong columns if table is modified during a session
Date: Wed, 24 Oct 2018 12:26:53 +0000
Message-ID: <15456-ac99771a43cdd95e@postgresql.org> (raw)

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.



Message-ID: <15456-ac99771a43cdd95e@postgresql.org>
Permalink:  ../15456-ac99771a43cdd95e@postgresql.org/
Also on:    postgresql.org/message-id/15456-ac99771a43cdd95e@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, sean.johnston@edgeintelligence.com
  Subject: Re: BUG #15456: Trigger function using ROW(NEW.*) has wrong columns if table is modified during a session
  In-Reply-To: <15456-ac99771a43cdd95e@postgresql.org>
  References: <15456-ac99771a43cdd95e@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox