pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lew <noone@lewscanon.com>
To: pgsql-sql@postgresql.org
Subject: Re: check constraint bug?
Date: Sat, 07 May 2011 08:52:21 -0400
Message-ID: <iq3fa3$b2o$1@news.albasani.net> (raw)
In-Reply-To: <BANLkTimt7GMbEgkRtLvKFy+kK8KDOnn2Og@mail.gmail.com>
References: <20110506060608.12bd24b0@dick.coachhouse>
	<BANLkTimt7GMbEgkRtLvKFy+kK8KDOnn2Og@mail.gmail.com>

Scott Marlowe wrote:
> Tarlika Elisabeth Schmitz wrote:
>> I specified:
>>
>> ALTER TABLE h ADD CONSTRAINT val_h_stats
>> CHECK (NOT (sex = 'f') AND (stats IS NOT NULL));
>>
>> which was translated to:
>>
>> ALTER TABLE h ADD CONSTRAINT val_h_stats
>> CHECK (NOT sex = 'f'::bpchar AND stats IS NOT NULL);

> You need another level of parens:
>
> CHECK (NOT ((sex = 'f') AND (stats IS NOT NULL)));

Because NOT has higher precedence than AND.

<http://www.postgresql.org/docs/9.0/interactive/sql-syntax-lexical.html#SQL-PRECEDENCE;

Note that equals (=), IS and NOTNULL have higher precedence than NOT.

So the CHECK expression Scott indicated is equivalent to the parenthesis-minimal

  CHECK ( NOT ( sex = 'f' AND stats IS NOT NULL ) )

or

  CHECK ( sex != 'f' OR stats IS NULL )

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg



view thread (3+ messages)

Message-ID: <iq3fa3$b2o$1@news.albasani.net>
Permalink:  ../iq3fa3$b2o$1@news.albasani.net/
Also on:    postgresql.org/message-id/iq3fa3$b2o$1@news.albasani.net

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: noone@lewscanon.com
  Subject: Re: check constraint bug?
  In-Reply-To: <iq3fa3$b2o$1@news.albasani.net>

* 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