5

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

Ratan Uday Kumar
  • 5,738
  • 6
  • 35
  • 54

1 Answers1

16

Use an in condition.

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