Re: pg_restore casts check constraints differently - Mailing list pgsql-general

From Tom Lane
Subject Re: pg_restore casts check constraints differently
Date
Msg-id 395.1459346495@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg_restore casts check constraints differently  (Amit Langote <amitlangote09@gmail.com>)
List pgsql-general
Amit Langote <amitlangote09@gmail.com> writes:
> destdb=# ALTER TABLE c ADD CONSTRAINT p_a_check CHECK (a IN ('a', 'b', 'c'));
> destdb=# \d c
> ...
> Check constraints:
>     "p_a_check" CHECK (a::text = ANY (ARRAY['a'::character varying,
> 'b'::character varying, 'c'::character varying]::text[]))

Hm.  It seems like the parser is doing something weird with IN there.
If you just do a simple comparison the constant ends up as TEXT to start
with:

regression=# CREATE TABLE pp (a varchar, CHECK (a = 'a'));
regression=# \d pp
...
Check constraints:
    "pp_a_check" CHECK (a::text = 'a'::text)

Or for that matter

regression=# CREATE TABLE p (a varchar, CHECK (a = any(array['a', 'b', 'c'])));
regression=# \d p
...
Check constraints:
    "p_a_check" CHECK (a::text = ANY (ARRAY['a'::text, 'b'::text, 'c'::text]))

I wonder why you don't get an array of text constants in the IN case.

            regards, tom lane


pgsql-general by date:

Previous
From: Amit Langote
Date:
Subject: Re: pg_restore casts check constraints differently
Next
From: Merlin Moncure
Date:
Subject: Re: Missed LIMIT clause pushdown in FDW API