在postrgesql 9.4中添加检查约束时出错

时间:2015-09-28 06:55:19

标签: database postgresql postgresql-9.4

我是postgresql的新手,我想在friend_type列上添加一个检查约束,但我收到错误,我正在尝试下面的查询

 ALTER TABLE itapp_friendlist ADD CONSTRAINT check_friend_type friend_type = ANY(0,1,2,3)

我也试过

 ALTER TABLE itapp_friendlist ADD CONSTRAINT check_friend_type (friend_type = ANY('{0,1,2,3}'::int[]))

但两个都给出了以下错误,请帮助我,我知道这不是一个大问题,但我是postgresql的新手,所以请原谅我提出这类问题,谢谢

ERROR:  syntax error at or near "friend_type"
LINE 1: ...itapp_friendlist ADD CONSTRAINT check_friend_type friend_typ...
                                                      ^

********** Error **********

ERROR: syntax error at or near "friend_type"
SQL state: 42601

1 个答案:

答案 0 :(得分:0)

对不起大家,我已经尝试了以下查询,现在工作正常,实际上我忘了添加check关键字

 ALTER TABLE itapp_friendlist ADD CONSTRAINT itapp_friendlist_type_check check (friend_type = ANY (ARRAY[0,1,2,3]))