Database 在postrgesql 9.4中添加检查约束时出错
我是postgresql的新手,我想在friend_type列上添加一个检查约束,但是我得到了错误,我正在尝试下面的查询Database 在postrgesql 9.4中添加检查约束时出错,database,postgresql,postgresql-9.4,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}
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
对不起大家,我再次尝试了下面的查询,现在它工作正常,实际上我忘记了添加
check
关键字
ALTER TABLE itapp_friendlist ADD CONSTRAINT itapp_friendlist_type_check check (friend_type = ANY (ARRAY[0,1,2,3]))