How to drop a subscription inside a stored procedure?

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема How to drop a subscription inside a stored procedure?
Дата
Msg-id 3918eb37-2971-401f-4697-a716105cbcb1@gmx.net
обсуждение исходный текст
Ответы Re: How to drop a subscription inside a stored procedure?  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
I am trying to write a stored procedure (Postgres 13) to enable
non-superusers to re-create a subscription.

For that, I essentially want to drop and re-create the subscription.
In order to be able to do that, the tables need to be empty.

So the approach is:

   Run a query to get all replicated tables, store this in an array.

   Run "drop subscription ..."

   Truncate all tables

   Run "create subscription ..."

However, the "drop subscription" part results in this error:

    ERROR:  DROP SUBSCRIPTION cannot be executed from a function
    CONTEXT:  SQL statement "drop subscription if exists my_replication"

I first thought that the initial SELECT to fetch all replicated tables,
starts an implicit transaction, so I removed everything else from the procedure,
including the dynamic SQL.

But even this very simple implementation:

    create or replace procedure drop_subscription()
    as
    $$
    begin
      drop subscription if exists test_subscription;
    end;
    $$
    security definer
    language plpgsql;


fails with that error.

Is there any way, I can provide a stored procedure to do this?

Regards
Thomas



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

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Row level security insert policy does not validate update new values/content?
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: How to drop a subscription inside a stored procedure?