我在 Postgres 9.1 中有简单的表创建脚本。仅当它不存在时,我才需要它来创建具有 2 属性 PK 的表。
CREATE TABLE IF NOT EXISTS "mail_app_recipients"
(
"id_draft" Integer NOT NULL,
"id_person" Integer NOT NULL
) WITH (OIDS=FALSE); -- this is OK
ALTER TABLE "mail_app_recipients" ADD PRIMARY KEY IF NOT EXISTS ("id_draft","id_person");
-- this is problem since "IF NOT EXISTS" is not allowed.
任何解决方案如何解决这个问题?提前致谢。