BUG #19907: INSERT through partitioned table fails with domain-typed generated column
BUG #19907: INSERT through partitioned table fails with domain-typed generated column
От:
PG Bug reporting form <noreply@postgresql.org>
Дата:
The following bug has been logged on the website:
Bug reference: 19907
Logged by: Bjorn Pagen
Email address: hello@bjornpagen.com
PostgreSQL version: Unsupported/Unknown
Operating system: macOS 27 (arm64)
Description:
On master (7fc2f04233), an INSERT through a partitioned table fails if
a CHECK constraint reads a stored generated column of a domain type:
CREATE DOMAIN d AS int;
CREATE TABLE p (k int, g d GENERATED ALWAYS AS (k * 2) STORED CHECK (g >
0))
PARTITION BY RANGE (k);
CREATE TABLE p1 PARTITION OF p FOR VALUES FROM (1) TO (10);
INSERT INTO p (k) VALUES (1);
ERROR: attribute 2 of type record has wrong type
DETAIL: Table has type integer, but query expects d.
The same happens when an index expression or predicate reads g. A
plain table, or an INSERT directly into p1, works.
This comes from 7c87284940: expand_insert_targetlist() now fills g
with a NULL of the domain's base type, and since the tuple is routed
without being copied into a slot of the table's rowtype, the CHECK
sees an integer where it expects d. With that commit reverted, the
INSERT works. I'll follow up with a patch.