| От | jboes@nexcerpt.com (Jeff Boes) |
|---|---|
| Тема | Re: CHECK constraint so that only one is TRUE? |
| Дата | |
| Msg-id | d40a65a1.0201150834.930d577@posting.google.com обсуждение исходный текст |
| Список | pgsql-general |
incognit@unifiedmind.com (+I) wrote in message news:<ebcd475a.0201121104.62d46853@posting.google.com>... > How would you write a check constraint to ensure that only one column, > of type boolean, is set to TRUE for a given ID? Need more info. Are you saying that a row has two or more boolean columns, and for each row you want to ensure that only one is TRUE? E.g., CREATE TABLE foo ( id integer not null, is_animal boolean not null, is_vegetable boolean not null, is_mineral boolean not null, check(?)); If this is the case, and you need a generic solution, you'd best write a function to compute it. There's a boolean expression for this, ((a xor b xor c) or (a xor b) and (b xor c) and (a xor c)) (and there's probably a shorter one) but it's hard to generalize it to N columns.
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера