From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
---|---|
To: | Vik Fearing <vik(dot)fearing(at)dalibo(dot)com> |
Cc: | ldrlj1 <russelljanusz(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: table constraint on two columns |
Date: | 2013-07-22 14:44:54 |
Message-ID: | 51ED4566.8060005@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 07/22/2013 07:16 AM, Vik Fearing wrote:
> 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.
An additional comment, did you put the check constraint on a column or
the table?
From the docs:
http://www.postgresql.org/docs/9.2/interactive/sql-createtable.html:
.. A check constraint specified as a column constraint should reference
that column's value only, while an expression appearing in a table
constraint can reference multiple columns...
>
>
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | ldrlj1 | 2013-07-22 14:53:01 | Re: table constraint on two columns |
Previous Message | Vik Fearing | 2013-07-22 14:16:43 | Re: table constraint on two columns |