【发布时间】:2012-04-11 23:52:33
【问题描述】:
我在 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.
任何解决方案如何解决这个问题?提前致谢。
【问题讨论】:
标签: sql postgresql primary-key alter-table postgresql-9.1