Re: BUG #13606: CHECK clause in CREATE TABLE command

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: p(dot)buongiovanni(at)net-international(dot)com
Cc: PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13606: CHECK clause in CREATE TABLE command
Date: 2015-09-02 10:59:06
Message-ID: CAB7nPqQAn0v+dXmSiW-CpMdt=YucJOy0FHkkrciV1hRbmoChgQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Sep 2, 2015 at 7:52 PM, <p(dot)buongiovanni(at)net-international(dot)com> wrote:
> CREATE TABLE draft.dummy1
> (
> cflag character(1) NOT NULL DEFAULT 'N'::bpchar,
> cfield character varying,
> CONSTRAINT _dummy1_ck1 CHECK (cflag = ANY (ARRAY['Y'::bpchar,
> 'N'::bpchar])),
> CONSTRAINT _dummy1_ck2 CHECK (cflag = 'N'::bpchar OR cflag = 'Y'::bpchar
> AND cfield IS NOT NULL)
> )
> WITH (
> OIDS=FALSE
> );
> ALTER TABLE draft.dummy1
> OWNER TO netdw_owner;
>
> As you can see brackets has been removed from the definition of the
> constraint _Dummy1_CK2. Clearly this doesn't work as I want.

AND has precedence over OR in such expressions, so this definition is
not wrong. In any case this is not a bug, just a matter of style, and
you could as well use pg_get_constraintdef with its pretty format to
get more parenthesis around those expressions, though this would need
modifications at pgadmin level I imagine.
--
Michael

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Vicky Soni - Quipment India 2015-09-02 12:21:38 Re: BUG #13601: bit as quoted column in output
Previous Message p.buongiovanni 2015-09-02 10:52:44 BUG #13606: CHECK clause in CREATE TABLE command