pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <kgrittn@ymail.com>
To: mv.gonzalez@cir.es <mv.gonzalez@cir.es>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #7924: Trigger update function don't take correct values
Date: Fri, 8 Mar 2013 11:03:33 -0800 (PST)
Message-ID: <1362769413.51869.YahooMailNeo@web162901.mail.bf1.yahoo.com> (raw)
In-Reply-To: <E1UDvch-0004Qr-4C@wrigleys.postgresql.org>
References: <E1UDvch-0004Qr-4C@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

"mv.gonzalez@cir.es" <mv.gonzalez@cir.es> wrote:

> On table_B appears:
>   id    | situation | when
> --------+-----------+---------------------
>   23    | Started  | 2013-03-08 12:33:35
>   23    | Started  | 2013-03-08 12:33:37
>
> I don't understand why after the second update, the insert done on table_B
> is incorrect, and has the same values that the first one.
>
> I've been looking for some kind of explanation like cache or something, but
> I couldn't find anything.

It helps to provide a self-containted test case like this:

test=# CREATE TABLE table_a (id int PRIMARY KEY, situation text NOT NULL);
CREATE TABLE
test=# INSERT INTO table_a VALUES (23, 'Unknown');
INSERT 0 1
test=# CREATE TABLE table_b (id int NOT NULL, sitation text NOT NULL, "when" timestamptz NOT NULL);
CREATE TABLE
test=# CREATE FUNCTION log_func()
test-#   RETURNS TRIGGER
test-#   LANGUAGE plpgsql
test-# AS $$
test$# BEGIN
test$#   set datestyle to 'sql';
test$#   set datestyle to 'european';
test$#   IF (TG_OP = 'UPDATE' and (OLD.situation!=NEW.situation)) THEN
test$#     INSERT INTO table_B VALUES (OLD.id,NEW.situation,NOW());
test$#   END IF;
test$#   RETURN NULL;
test$# END;
test$# $$;
CREATE FUNCTION
test=# CREATE TRIGGER log_trig
test-#   AFTER UPDATE ON table_a
test-#   FOR EACH ROW EXECUTE PROCEDURE log_func();
CREATE TRIGGER
test=# update table_A set situation='Started' where id='23';
UPDATE 1
test=# select * from table_a;
 id | situation
----+-----------
 23 | Started
(1 row)

test=# select * from table_b;
 id | sitation |              when             
----+----------+--------------------------------
 23 | Started  | 08/03/2013 13:01:08.169213 CST
(1 row)

test=# update table_A set situation='Waiting' where id='23';
UPDATE 1
test=# select * from table_a;
 id | situation
----+-----------
 23 | Waiting
(1 row)

test=# select * from table_b;
 id | sitation |              when             
----+----------+--------------------------------
 23 | Started  | 08/03/2013 13:01:08.169213 CST
 23 | Waiting  | 08/03/2013 13:01:08.179754 CST
(2 rows)

How about showing us yours?

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (2+ messages)

Message-ID: <1362769413.51869.YahooMailNeo@web162901.mail.bf1.yahoo.com>
Permalink:  ../1362769413.51869.YahooMailNeo@web162901.mail.bf1.yahoo.com/
Also on:    postgresql.org/message-id/1362769413.51869.YahooMailNeo@web162901.mail.bf1.yahoo.com

 · 

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: kgrittn@ymail.com, mv.gonzalez@cir.es
  Subject: Re: BUG #7924: Trigger update function don't take correct values
  In-Reply-To: <1362769413.51869.YahooMailNeo@web162901.mail.bf1.yahoo.com>
  References: <E1UDvch-0004Qr-4C@wrigleys.postgresql.org> <1362769413.51869.YahooMailNeo@web162901.mail.bf1.yahoo.com>

* 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