| От | Tom Lane |
|---|---|
| Тема | Re: questions about query design |
| Дата | |
| Msg-id | 3098.1174576261@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: questions about query design (Alban Hertroys <alban@magproductions.nl>) |
| Список | pgsql-general |
Alban Hertroys <alban@magproductions.nl> writes:
> Ottavio Campana wrote:
>> What I want to do is a function inserting a new item into the table
>> ensuring that there is only one record in the table having a particular
>> description and at the same time the active field set to true (it might
>> seem stupid, but the application requires it).
> Assuming active can't be NULL, what's wrong with a UNIQUE constraint on
> (description, active)?
I think he does not want descriptions to be unique among non-active
entries. If so, the right thing is a partial unique index:
CREATE UNIQUE INDEX ... on (description) WHERE active;
regards, tom lane
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера