Hinzufügen Primärschlüssel zu PostgreSQL-Tabelle nur, wenn es nicht vorhanden ist

Habe ich eine einfache Tabelle erstellen-script in Postgres 9.1. Ich brauche Sie zum erstellen der Tabelle mit
2-Attribute PK nur, wenn es nicht vorhanden ist.

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.

Keine Lösung wie dieses problem zu lösen? Vielen Dank im Voraus.

InformationsquelleAutor Pavel S. | 2012-03-28
Schreibe einen Kommentar