Expression of check constraint

From: Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Expression of check constraint
Date: 2019-07-04 05:58:56
Message-ID: DDD8FEB9-CCE9-4951-9022-A58DCC2998C4@mikatiming.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

[cid:image001_d0a5cf51-5dd3-4ff5-b428-1016a6d95a0f.png]

mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany

fon +49 2202 2401-1197
dirk(dot)mika(at)mikatiming(dot)de
www.mikatiming.de

AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika

[cid:CCh2U_f27a5ce6-8556-4db1-8aa4-fd610d6e9efe.jpg]<https://youtu.be/qfOFXrpSKLQ>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message rob stone 2019-07-04 08:49:59 Re: Expression of check constraint
Previous Message Souvik Bhattacherjee 2019-07-04 01:11:43 Re: Allocating shared memory in Postgres