Re: table constraint on two columns

Поиск
Список
Период
Сортировка
От Vik Fearing
Тема Re: table constraint on two columns
Дата
Msg-id 51ED3ECB.5020703@dalibo.com
обсуждение исходный текст
Ответ на table constraint on two columns  (ldrlj1 <russelljanusz@yahoo.com>)
Ответы Re: table constraint on two columns  (Adrian Klaver <adrian.klaver@gmail.com>)
Re: table constraint on two columns  (ldrlj1 <russelljanusz@yahoo.com>)
Список pgsql-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.



В списке pgsql-sql по дате отправления:

Предыдущее
От: ldrlj1
Дата:
Сообщение: table constraint on two columns
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: table constraint on two columns