3

Given:

CREATE TABLE my_table
(
    my_table_id serial NOT NULL PRIMARY KEY,
    flag_one boolean NOT NULL,
    flag_two boolean NOT NULL
);

Is there a way to create a check constraint to ensure that flag_one and flag_two cannot both be true? Both are allowed to be false and one or the other may be true.

Paul Croarkin
  • 14,496
  • 14
  • 79
  • 118

1 Answers1

4
CREATE TABLE my_table
(
    my_table_id serial NOT NULL PRIMARY KEY,
    flag_one boolean NOT NULL,
    flag_two boolean NOT NULL,

    check ( not (flag_one is true and flag_two is true) )
);
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152