pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vik Fearing <vik.fearing@dalibo.com>
To: ldrlj1 <russelljanusz@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: table constraint on two columns
Date: Mon, 22 Jul 2013 16:16:43 +0200
Message-ID: <51ED3ECB.5020703@dalibo.com> (raw)
In-Reply-To: <1374501921767-5764645.post@n5.nabble.com>
References: <1374501921767-5764645.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

On 07/22/2013 04:05 PM, ldrlj1 wrote:
> Postgres 9.2.4.
>
> I have two columns, approved and comments. Approved is a boolean with no
> default value and comments is a character varying (255) and nullable.
>
> I am trying to create a constraint that will not allow a row to be entered
> if approved is set to false and comments is null.

CHECK constraints work on positives, so restate your condition that
way.  A row is permissible if approved is true or the comments are not
null, correct?  So...

...add constraint chk_comments (approved or comments is not null)...

> This does not work. yada, yada, yada... add constraint "chk_comments' check
> (approved = false and comments is not null). The constraint is successfully
> added, but does not work as I expected.

That's not the same check as what you described.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (4+ messages)  latest in thread

Message-ID: <51ED3ECB.5020703@dalibo.com>
Permalink:  ../51ED3ECB.5020703@dalibo.com/
Also on:    postgresql.org/message-id/51ED3ECB.5020703@dalibo.com

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: vik.fearing@dalibo.com, russelljanusz@yahoo.com
  Subject: Re: table constraint on two columns
  In-Reply-To: <51ED3ECB.5020703@dalibo.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