public inbox for [email protected]
help / color / mirror / Atom feedFrom: SATYANARAYANA NARLAPURAM <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value)
Date: Sun, 12 Apr 2026 18:59:28 -0700
Message-ID: <CAHg+QDexGTmCZzx=73gXkY2ZADS6LRhpnU+-8Y_QmrdTS6yUhA@mail.gmail.com> (raw)
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
view thread (16+ messages) latest in thread
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Bug: Rule actions see wrong values for generated columns (NEW.gen reads OLD value)
In-Reply-To: <CAHg+QDexGTmCZzx=73gXkY2ZADS6LRhpnU+-8Y_QmrdTS6yUhA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox