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

From: Bjorn Pagen <hello(at)bjornpagen(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19907: INSERT through partitioned table fails with domain-typed generated column
Date: 2026-11-16 12:38:45
Message-ID: CAARz7_hOquSbr06e=3t+iC9zSPVHO9LT-oaO4LJatj2tnK7WVw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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(at)postgresql(dot)org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference: 19907
> Logged by: Bjorn Pagen
> Email address: hello(at)bjornpagen(dot)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.
>
>
>

Attachment Content-Type Size
v1-0001-Give-a-generated-column-s-placeholder-NULL-the-co.patch text/x-patch 7.8 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-11-16 13:08:12 RE: BUG #19892: Logical replication skips UPDATE/DELETE of rows with NULL in a hash-indexed subscriber column
Previous Message PG Bug reporting form 2026-11-16 12:24:25 BUG #19907: INSERT through partitioned table fails with domain-typed generated column