| From: | Junwang Zhao <zhjwpku(at)gmail(dot)com> |
|---|---|
| To: | zheng_xianghang(at)163(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19442: PL/pgSQL: domain over composite type bypasses type validation when assigning NULL (PostgreSQL 18.3) |
| Date: | 2026-03-30 14:39:23 |
| Message-ID: | CAEG8a3KMOS2dGzOYaZqDPZL+HOrYoAab50T4VYmWFGUWx7YZjg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Mon, Mar 30, 2026 at 7:52 PM PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 19442
> Logged by: Xianghang Zheng
> Email address: zheng_xianghang(at)163(dot)com
> PostgreSQL version: 18.3
> Operating system: Linux x86_64
> Description:
>
> I found an issue on PostgreSQL 18.3 related to domain handling over
> composite types in PL/pgSQL.
> After the fix for BUG #18735, the "cache lookup failed for type 0" error no
> longer occurs, but a new correctness problem arises:
> When assigning a NULL composite variable to a domain over composite type in
> PL/pgSQL,
> the domain's type validation and coercion logic is bypassed.
> This indicates an incomplete fix and may lead to incorrect enforcement of
> domain constraints (CHECK, NOT NULL, etc.) in the future.
> Version: PostgreSQL 18.3
> Test case:
> CREATE TYPE comp AS (a int, b text);
> CREATE DOMAIN dcomp AS comp;
> CREATE OR REPLACE FUNCTION test_domain_bug()
> RETURNS dcomp
> AS $$
> DECLARE
> v_comp comp := NULL;
> v_dcomp dcomp;
> BEGIN
> v_dcomp := v_comp;
> RETURN v_dcomp;
> END;
> $$ LANGUAGE plpgsql;
> SELECT test_domain_bug();
> Actual result: NULL (no error)
> Expected result: Domain type coercion should be properly executed even for
> NULL values.
dcomp doesn't have the not null constraint, so I think this is ok?
I tried `CREATE DOMAIN dcomp AS comp not null;`, it does report error:
[local] zhjwpku(at)postgres:5432-20309=# SELECT test_domain_bug();
ERROR: domain dcomp does not allow null values
CONTEXT: PL/pgSQL function test_domain_bug() line 4 during statement
block local variable initialization
Time: 2.730 ms
> This is a regression caused by incomplete backpatch of BUG #18735.
>
>
>
>
--
Regards
Junwang Zhao
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Junwang Zhao | 2026-03-30 14:56:55 | Re: BUG #19445: Domain DEFAULT not recorded in pg_attrdef (atthasdef false) in PostgreSQL 18.3 |
| Previous Message | Junwang Zhao | 2026-03-30 14:17:19 | Re: BUG #19444: conkey field empty for domain NOT NULL constraint in pg_constraint (18.3) |