Ho uno script di creazione di tabelle semplice in Postgres 9.1. Mi serve per creare la tabella con PK a 2 attributi solo se non esiste.Aggiungere la chiave primaria alla tabella PostgreSQL solo se non esiste
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.
Qualche soluzione su come risolvere questo problema? Grazie in anticipo.
Grazie, questo è quello che stavo cercando. Separare ADD PRIMARY KEY SE NON ESISTE è impossibile? –
No, non esiste l'opzione 'SE NON ESISTE' per l'istruzione' ALTER TABLE'. –