Privilege required for IF EXISTS event if the object already exists

Поиск
Список
Период
Сортировка
От Shay Rojansky
Тема Privilege required for IF EXISTS event if the object already exists
Дата
Msg-id CADT4RqC99JiYHs3sOwmoxemzYEfUFwGDw2sFrz7FoGCOyX3_cw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Privilege required for IF EXISTS event if the object already exists  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Privilege required for IF EXISTS event if the object already exists  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список 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

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Brar Piening
Дата:
Сообщение: Re: Add id's to various elements in protocol.sgml
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: [PATCH] proposal for regexp_count, regexp_instr, regexp_substr and regexp_replace