| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | 1548140642(at)qq(dot)com |
| Subject: | BUG #19947: Rules see parent generated expression instead of routed partition's expression |
| Date: | 2026-11-25 17:22:24 |
| Message-ID: | 19947-518c4b68bb521e75@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19947
Logged by: Milo
Email address: 1548140642(at)qq(dot)com
PostgreSQL version: 19.0
Operating system: Linux/amd64
Description:
Rule actions on a partitioned table evaluate NEW generated columns using the
parent's generation expression, even when the row is routed to a partition
with a different expression. The value seen by the rule then differs from
the value physically stored.
Run as a superuser:
CREATE TABLE p (
k integer NOT NULL,
a integer,
g integer GENERATED ALWAYS AS (a * 2) STORED
) PARTITION BY LIST (k);
CREATE TABLE c
PARTITION OF p (
g WITH OPTIONS GENERATED ALWAYS AS (a * 3) STORED
) FOR VALUES IN (1);
CREATE TABLE rule_log (
phase text,
observed_g integer
);
CREATE RULE p_ins AS
ON INSERT TO p
DO ALSO INSERT INTO rule_log VALUES ('insert', NEW.g);
CREATE RULE p_upd AS
ON UPDATE TO p
DO ALSO INSERT INTO rule_log VALUES ('update', NEW.g);
INSERT INTO p (k, a) VALUES (1, 10);
UPDATE p SET a = 20 WHERE k = 1;
SELECT 'physical' AS source, g AS value
FROM c
UNION ALL
SELECT phase, observed_g
FROM rule_log
ORDER BY source;
The result is:
source | value
----------+-------
insert | 20
physical | 60
update | 40
(3 rows)
The generated-columns documentation says: "For a stored generated column,
the generation expression that is actually applied during insert or update
is the one associated with the table that the row is physically in."
Since the row is physically stored in c, whose expression is a * 3, I expect
the rule to observe 30 on insert and 60 on update.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PG Bug reporting form | 2026-11-25 17:26:07 | BUG #19948: Unqualified prefix <= operator is rejected despite being first in search_path |
| Previous Message | PG Bug reporting form | 2026-11-25 17:18:42 | BUG #19946: Caught foreign-key violations retain RI fast-path memory until transaction end |