From: | Shay Rojansky <roji(at)roji(dot)org> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Privilege required for IF EXISTS event if the object already exists |
Date: | 2021-12-15 12:35:24 |
Message-ID: | CADT4RqC99JiYHs3sOwmoxemzYEfUFwGDw2sFrz7FoGCOyX3_cw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi all,
I've received numerous complaints about CREATE SCHEMA IF NOT EXISTS failing
when the user lacks CREATE privileges on the database - even if the schema
already exists. A typical scenario would be a multi-tenant
schema-per-tenant setup, where the schema and tenant user are created
beforehand, but then some database layer or ORM wants to ensure that the
schema is there so the above is issued.
Would it be reasonable to have the above no error if the schema already
exists? That would make it similar to the following (which I'm switching to
in the Entity Framework Core ORM):
DO $$
BEGIN
IF NOT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = 'foo') THEN
CREATE SCHEMA "foo";
END IF;
END $$;
The same could apply to other CREATE ... IF NOT EXISTS variations.
Shay
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2021-12-15 12:41:16 | Re: [PATCH] proposal for regexp_count, regexp_instr, regexp_substr and regexp_replace |
Previous Message | Brar Piening | 2021-12-15 11:07:47 | Re: Add id's to various elements in protocol.sgml |