From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michel Pelletier <pelletier.michel@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Is there a way to detect that code is inside CREATE EXTENSION?
Date: Tue, 13 Dec 2022 13:49:07 -0500
Message-ID: <2448383.1670957347@sss.pgh.pa.us> (raw)
In-Reply-To: <CACxu=vL28Rew2P6TP05BdUS3m9J5-7H3rgbsa_GTBd6X+o=GZw@mail.gmail.com>
References: <CACxu=vL28Rew2P6TP05BdUS3m9J5-7H3rgbsa_GTBd6X+o=GZw@mail.gmail.com>
Michel Pelletier <pelletier.michel@gmail.com> writes:
> I'm working with an event trigger that fires on ALTER TABLE and regenerates
> certain objects, but unfortunately those objects end up being owned by any
> extensions that run ALTER TABLE and any subsequent alterations fail to
> regenerate because they are owned by that extension.
> Ideally, I'd like to be able to detect inside my trigger if I'm being
> called from CREATE EXTENSION or not, but I can't find any obvious way to
> detect that.
At the C-code level you can check the creating_extension global variable,
or maybe better look at the in_extension fields of CollectedCommands.
I don't think we expose that state at the SQL level, but it's pretty
hard to make a useful event trigger without writing any C ...
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, pelletier.michel@gmail.com
Subject: Re: Is there a way to detect that code is inside CREATE EXTENSION?
In-Reply-To: <2448383.1670957347@sss.pgh.pa.us>
References: <CACxu=vL28Rew2P6TP05BdUS3m9J5-7H3rgbsa_GTBd6X+o=GZw@mail.gmail.com> <2448383.1670957347@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox