Re: Is there a way to detect that code is inside CREATE EXTENSION?

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michel Pelletier <pelletier(dot)michel(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Is there a way to detect that code is inside CREATE EXTENSION?
Date: 2022-12-13 18:58:33
Message-ID: CAOBaU_a1uhzsccK1nD_ORacrWVFYBgkLM6_SReHzPspjpehi1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Dec 13, 2022 at 7:49 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Michel Pelletier <pelletier(dot)michel(at)gmail(dot)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 ...

AFAICS it's exposed in pg_event_trigger_ddl_commands().in_extension.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michel Pelletier 2022-12-13 18:59:07 Re: Is there a way to detect that code is inside CREATE EXTENSION?
Previous Message Tom Lane 2022-12-13 18:49:07 Re: Is there a way to detect that code is inside CREATE EXTENSION?