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.jp/document/12/html/ddl-constraints.html#DDL-CONSTRAINTS-CHECK-CONSTRAINTS


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS