Re: UPDATE with invalid domain constraint - Mailing list pgsql-hackers

From jian he
Subject Re: UPDATE with invalid domain constraint
Date
Msg-id CACJufxGYwfzK-WH2FKtyaKzUAht_KjimGPzkspc4g5RHoerpmQ@mail.gmail.com
Whole thread Raw
In response to UPDATE with invalid domain constraint  (jian he <jian.universality@gmail.com>)
Responses Re: UPDATE with invalid domain constraint
List pgsql-hackers
On Tue, Aug 19, 2025 at 10:08 PM jian he <jian.universality@gmail.com> wrote:
>

> drop table if exists dt1;
> drop domain if exists d1;
> create domain d1 as int;
> create table dt1(i int, c d1);
> insert into dt1 values(1,2);
> alter domain d1 add constraint cc check(value <> 2) not valid;
>

> update dt1 set i = i + 1;
> update dt1 set c = c;
> update dt1 set i = i + 1, c = c;
> update dt1 set i = i + 1, c = c::d1;
>
> Should the four statements above result in an error?
> This only happens with UPDATE, since INSERT will check with domain
> invalid constraints.

the main idea is that
if we find out that a Var Node type is domain with invalid constraint
then we convert the
Var to CoerceToDomain node.


explain (verbose, costs off) update dt1 set i = i + 1;
            QUERY PLAN
----------------------------------
 Update on public.dt1
   ->  Seq Scan on public.dt1
         Output: (i + 1), c, ctid
(3 rows)

as you can see from the "Output:", column "c" is also here,
In rewriteTargetListIU, In rewriteTargetListIU, I use makeTargetEntry to produce
a new TargetEntry for column c, set its expr to a CoerceToDomain node, and set
resjunk to true.

Attachment

pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: [WIP]Vertical Clustered Index (columnar store extension) - take2
Next
From: John Naylor
Date:
Subject: Re: New commitfest app release on August 19th