CHECK制約CREATE TABLE t1 ( gender TEXT CHECK ( gender IN ( 'man', 'woman' ) ) ); => genderカラムにCHECK制約を設定 INSERT INTO t1 VALUES ( 'man' ); => OK INSERT INTO t1 VALUES ( 'woman' ); => OK INSERT INTO t1 VALUES ( 'foo' ); ERROR: new row for relation "t1" violates check constraint "t1_gender_check" DETAIL: Failing row contains (foo). テーブル定義テーブル "public.t1" 列 | 型 | 修飾語 --------+------+-------- gender | text | 検査制約: "t1_gender_check" CHECK (gender = ANY (ARRAY['man'::text, 'woman'::text])) 参考https://www.postgresql.org/docs/current/ddl-constraints.html |
|