Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value) - Mailing list pgsql-hackers

From SATYANARAYANA NARLAPURAM
Subject Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value)
Date
Msg-id CAHg+QDexGTmCZzx=73gXkY2ZADS6LRhpnU+-8Y_QmrdTS6yUhA@mail.gmail.com
Whole thread
Responses Re: Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value)
List pgsql-hackers
Hi hackers,

NEW.<generated_coulmn> is resolved to the OLD row's value
for update or NULL for insert cases in a DO ALSO rule action for
generated columns.  This bug affects both stored and virtual 
generated columns. Reporting here to see if this is a known issue
with generated columns.

Repro:

CREATE TABLE t (id int PRIMARY KEY, a int,
                gen int GENERATED ALWAYS AS (a * 2) VIRTUAL);
CREATE TABLE t_log (op text, old_gen int, new_gen int);

CREATE RULE t_log AS ON UPDATE TO t
  DO ALSO INSERT INTO t_log VALUES ('UPD', OLD.gen, NEW.gen);

INSERT INTO t (id, a) VALUES (1, 5); 
UPDATE t SET a = 100 WHERE id = 1; 

postgres=# SELECT * FROM t;
 id |  a  | gen
----+-----+-----
  1 | 100 | 200
(1 row)

postgres=# SELECT * FROM t_log;
 op  | old_gen | new_gen
-----+---------+---------
 UPD |      10 |      10
(1 row)

Thanks,
Satya

pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: DELETE/UPDATE FOR PORTION OF with rule system is not working
Next
From: Peter Smith
Date:
Subject: Re: EXCEPT TABLE - Case inconsistency for describe \d and \dRp+