From: rob stone <floriparob@gmail.com>
To: Dirk Mika <Dirk.Mika@mikatiming.de>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Expression of check constraint
Date: Thu, 04 Jul 2019 18:49:59 +1000
Message-ID: <421a8b3052781f2419b0928f4523fb3731e8a913.camel@gmail.com> (raw)
In-Reply-To: <DDD8FEB9-CCE9-4951-9022-A58DCC2998C4@mikatiming.de>
References: <DDD8FEB9-CCE9-4951-9022-A58DCC2998C4@mikatiming.de>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: floriparob@gmail.com, Dirk.Mika@mikatiming.de
Subject: Re: Expression of check constraint
In-Reply-To: <421a8b3052781f2419b0928f4523fb3731e8a913.camel@gmail.com>
References: <DDD8FEB9-CCE9-4951-9022-A58DCC2998C4@mikatiming.de> <421a8b3052781f2419b0928f4523fb3731e8a913.camel@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox