Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value)
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
From: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-13T01:59:28Z
Lists: 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
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix incorrect NEW references to generated columns in rule rewriting
- 8e39951beac7 14.23 landed
- 7062bd577ec9 15.18 landed
- 07b257189ea4 16.14 landed
- 9d6208939a0a 17.10 landed
- e528bfe97190 18.4 landed
- c6a79be3f3c7 19 (unreleased) landed