Ratan Uday Kumar
Ratan Uday Kumar

Reputation: 6492

how to use check constraint in postgresql for string

i am new to postgres

how to create table with check constraint for column name say polluted which only have to accept 'yes' or 'no' values on insert.

for other values it should promote error message

My table name is vehicles

Upvotes: 6

Views: 9832

Answers (1)

user330315
user330315

Reputation:

Use an in condition.

create table vehicles
(
  id integer primary key, 
  polluted text not null check (polluted in ('yes', 'no'))
);

Upvotes: 19

Related Questions