Re: Alter Table from Trigger - Mailing list pgsql-novice

From David G. Johnston
Subject Re: Alter Table from Trigger
Date
Msg-id CAKFQuwYAUiBR-5c6wP=NCQt1G8OPpXAxuL9k6CXuvcyggF70BQ@mail.gmail.com
Whole thread Raw
In response to Alter Table from Trigger  (Tamara Tardif <tamara@ccxtechnologies.com>)
List pgsql-novice
On Thu, Mar 19, 2020 at 9:32 AM Tamara Tardif <tamara@ccxtechnologies.com> wrote:
Hello,

Is altering a table from its own trigger possible? If not, how come?

For context, I am trying to attach a partition to a table using a trigger on that same table. Here is the error:

ERROR:  cannot ALTER TABLE "tablename" because it is being used by active queries in this session

Any help would be greatly appreciated. 

The error message answers both of your questions.  The rule is that structure is constant while queries are running.  The various lock types handle this and cause queries in different sessions to queue up.  If you try and break things within the same session you end up with something like the error message shown instead as queuing won't help.

Whether there is a workable way to accomplish your goal I do not know.

David J.

pgsql-novice by date:

Previous
From: Tamara Tardif
Date:
Subject: Alter Table from Trigger
Next
From: Roberto Taglia
Date:
Subject: Another view