如何在postgresql中对字符串使用检查约束

how to use check constraint in postgresql for string

我是 postgres 的新手

如何为列名创建带有检查约束的 table 说 polluted 插入时只需要接受 'yes' 或 'no' 值.

对于其他值,它应该提示错误消息

我的table名字是车辆

使用 in 条件。

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