From: | rob stone <floriparob(at)gmail(dot)com> |
---|---|
To: | Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Expression of check constraint |
Date: | 2019-07-04 08:49:59 |
Message-ID: | 421a8b3052781f2419b0928f4523fb3731e8a913.camel@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
On Thu, 2019-07-04 at 05:58 +0000, Dirk Mika wrote:
> Hi,
>
> if I add the following check constraint to a table:
>
> ALTER TABLE public.times_places
> ADD CONSTRAINT ck_tp_ratified CHECK
> (ratified IS NULL OR (ratified IN ('Y', 'N')));
>
> It becomes the following when describing the table in psql:
>
> Check constraints:
> "ck_tp_ratified" CHECK (ratified IS NULL OR (ratified::text = ANY
> (ARRAY['Y'::character varying, 'N'::character varying]::text[])))
>
> The behavior of the check constraint is logically identical and this
> seems plausible to me, but I still wonder why:
> 1. does the expression x in (a, b) become the expression x =
> any(array(a, b)?
> 2. why is the array expression casted so wildly? First to
> character varying and then to text[]?
> 3. The column ratified is of type character varying(1). Why is it
> casted to text?
>
> Dirk
> --
> Dirk Mika
> Software Developer
>
>
Why don't you define "ratified" as CHAR(1)?
AFAIK, constraint evaluation is based upon the column's underlying data
type.
Cheers,
Robert
From | Date | Subject | |
---|---|---|---|
Next Message | Dirk Mika | 2019-07-04 08:57:01 | Re: Expression of check constraint |
Previous Message | Dirk Mika | 2019-07-04 05:58:56 | Expression of check constraint |