BUG #19907: INSERT through partitioned table fails with domain-typed generated column

Started by PG Bug reporting form12 days ago2 messagesbugs

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1PG 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.

#2Bjorn Pagen
hello@bjornpagen.com
In reply to: PG Bug reporting form (#1)
Re: BUG #19907: INSERT through partitioned table fails with domain-typed generated column

Here's a patch. It keeps the bare NULL Const but labels it with the
column's own type, so the domain's constraints are still not applied
to it.

--
Bjorn Pagen

On Mon, Nov 16, 2026 06:25 AM, PG Bug reporting form <noreply@postgresql.org>
wrote:

Show quoted text

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.

Attachments:

t259251_2
v1-0001-Give-a-generated-column-s-placeholder-NULL-the-co.patchtext/x-patch; charset=UTF-8; name=v1-0001-Give-a-generated-column-s-placeholder-NULL-the-co.patchDownload+26-15