Re: CHECK constraint so that only one is TRUE?
Re: CHECK constraint so that only one is TRUE?
От:
jboes@nexcerpt.com (Jeff Boes)
Дата:
incognit@unifiedmind.com (+I) wrote in message news:... > 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.