Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Restrict two specific column values from existing at the same time

$
0
0

I have a PostgreSQL example table where at most one row that is not of type ‘c’ should be allowed.

I would appreciate any help creating a constraint that will enforce this.

CREATE TABLE example
(
  example_id    serial PRIMARY KEY,
  example_state CHAR(1) NOT NULL
);

ALTER TABLE example ADD CONSTRAINT 
  example_constraint
CHECK (example_state = 'a' OR example_state = 'b' OR example_state = 'c');

Viewing all articles
Browse latest Browse all 1138

Latest Images

Trending Articles



Latest Images