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