嗨,我似乎无法以我期望的方式在postgreSQL中获得约束。从pgadmin内部,我执行以下SQL查询。
-- Check: "TypeCheck"
-- ALTER TABLE "ComLog" DROP CONSTRAINT "TypeCheck";
ALTER TABLE "ComLog"
ADD CONSTRAINT "TypeCheck" CHECK ("Type" SIMILAR TO 'email|post|IRL|minutes');
COMMENT ON CONSTRAINT "TypeCheck" ON "ComLog" IS 'One of email|post|IRL|minutes';
执行后将转换为。
-- Check: "TypeCheck"
-- ALTER TABLE "ComLog" DROP CONSTRAINT "TypeCheck";
ALTER TABLE "ComLog"
ADD CONSTRAINT "TypeCheck" CHECK ("Type" ~ similar_escape('email|post|IRL|minutes'::text, NULL::text));
COMMENT ON CONSTRAINT "TypeCheck" ON "ComLog" IS 'One of email|post|IRL|minutes';
我希望这会将我对“类型”列的输入限制为电子邮件发布IRL或分钟数之一。但是,当输入表数据时,当我输入这些类型之一时,此约束将失败。“类型”列为字符类型。有谁知道如何解决这一问题。谢谢。
CHECK (type in ('email','post','IRL','minutes')
?