Re: Alternative to Select in table check constraint

Поиск
Список
Период
Сортировка
Искать
От
Michael Glaesemann
Тема
Re: Alternative to Select in table check constraint
Дата
Msg-id
4FA18A22-AFC2-4C6A-A487-57DAEF09F59F@seespotcode.net
Ответ на
Список
Дерево обсуждения
Alternative to Select in table check constraint Richard Broersma Jr <rabroersma@yahoo.com>
Re: Alternative to Select in table check constraint Tom Lane <tgl@sss.pgh.pa.us>
Re: Alternative to Select in table check constraint Richard Broersma Jr <rabroersma@yahoo.com>
Re: Alternative to Select in table check constraint Michael Glaesemann <grzm@seespotcode.net>
Re: Alternative to Select in table check constraint Richard Broersma Jr <rabroersma@yahoo.com>
Re: Alternative to Select in table check constraint Rod Taylor <pg@rbt.ca>
Re: Alternative to Select in table check constraint Richard Broersma Jr <rabroersma@yahoo.com>
Re: Alternative to Select in table check constraint Andreas Joseph Krogh <andreak@officenet.no>
Re: Alternative to Select in table check constraint Erik Jones <erik@myemma.com>
Re: Alternative to Select in table check constraint "Aaron Bono" <postgresql@aranya.com>
Re: Alternative to Select in table check constraint Richard Broersma Jr <rabroersma@yahoo.com>

On Jul 1, 2006, at 6:55 , Richard Broersma Jr wrote:

>         CHECK   ( 1 = ALL (     SELECT COUNT(STATUS)
>                                 FROM BADGES
>                                 WHERE STATUS = 'A'
>                                 GROUP BY EMPNO))
From the PostgreSQL docs (http://www.postgresql.org/docs/8.1/ 
interactive/sql-createtable.html)

> Currently, CHECK expressions cannot contain subqueries nor refer to  
> variables other than columns of the current row.

This is why the the above won't work. You can probably do something  
similar by creating UNIQUE index with a WHERE clause. For example (if  
I'm understanding the intent),

CREATE UNIQUE INDEX one_a_badge_per_employee_idx
ON badges (empno)
WHERE status = 'A';

Here are links to more documentation on indexes:

http://www.postgresql.org/docs/8.1/interactive/sql-createindex.html
http://www.postgresql.org/docs/8.1/interactive/indexes-partial.html

Hope this helps.

Michael Glaesemann
grzm seespotcode net




В списке pgsql-sql по дате отправления
От: Richard Broersma Jr
Дата:
Сообщение: Re: How To Exclude True Values
От: Richard Broersma Jr
Дата:
FAQ