UPDATE with invalid domain constraint

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: UPDATE with invalid domain constraint
Date: 2025-08-19 14:08:21
Message-ID: CACJufxE2oFcLmrqDrqJrH5k03fv+v9=+-PBs-mV5WsJ=31XMyw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

should UPDATE statement need to verify that the domain value is satisfied with
invalid domain constraints?
Álvaro Herrera already mentioned this in [1], but I just want to confirm it.

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.

this ``update dt1 set i = i + 1, c = 2;``
do return error, which is expected.

[1]: https://postgr.es/m/202508140957.4daktvyr7xiw@alvherre.pgsql

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nazir Bilal Yavuz 2025-08-19 14:14:54 Re: Speed up COPY FROM text/CSV parsing using SIMD
Previous Message Andres Freund 2025-08-19 13:56:27 Re: VM corruption on standby