Re: domain check constraint should also consider domain's collation - Mailing list pgsql-hackers

From Tom Lane
Subject Re: domain check constraint should also consider domain's collation
Date
Msg-id 610466.1752502420@sss.pgh.pa.us
Whole thread Raw
In response to domain check constraint should also consider domain's collation  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
jian he <jian.universality@gmail.com> writes:
> CREATE COLLATION case_insensitive (provider = icu, locale =
> '@colStrength=secondary', deterministic = false);
> SELECT 'a' = 'A' COLLATE case_insensitive;
> CREATE DOMAIN d1 as text collate case_insensitive check (value <> 'a');
> SELECT 'A'::d1;

> ``SELECT 'A'::d1`` should error out as domain check constraint not satisfied?

No.  In the above, 'value' is of type text, not type d1, and therefore
that comparison will use the default collation.  If you try to make it
do something else, you will break far more than you fix.  (The
fundamental reason why this is important is that we cannot assume that
the domain constraints hold for the value until after we complete the
CHECK expressions.)  So the correct way to create a domain that works
as you have in mind is

CREATE DOMAIN d1 as text collate case_insensitive
    check (value <> 'a' COLLATE case_insensitive);

            regards, tom lane



pgsql-hackers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: Missing NULL check after calling ecpg_strdup
Next
From: "Burd, Greg"
Date:
Subject: Re: Changing shared_buffers without restart