pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Is there a way to detect that code is inside CREATE EXTENSION?
4+ messages / 3 participants
[nested] [flat]

* Is there a way to detect that code is inside CREATE EXTENSION?
@ 2022-12-13 18:39 Michel Pelletier <pelletier.michel@gmail.com>
  2022-12-13 18:49 ` Re: Is there a way to detect that code is inside CREATE EXTENSION? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Michel Pelletier @ 2022-12-13 18:39 UTC (permalink / raw)
  To: pgsql-general

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.  I hope this isn't obvious and I just missed something in the
documentation.  Does anyone have any pointers or hacks they know of that
can accomplish this?

Thanks,

-Michel

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Is there a way to detect that code is inside CREATE EXTENSION?
  2022-12-13 18:39 Is there a way to detect that code is inside CREATE EXTENSION? Michel Pelletier <pelletier.michel@gmail.com>
@ 2022-12-13 18:49 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-12-13 18:58   ` Re: Is there a way to detect that code is inside CREATE EXTENSION? Julien Rouhaud <rjuju123@gmail.com>
  2022-12-13 18:59   ` Re: Is there a way to detect that code is inside CREATE EXTENSION? Michel Pelletier <pelletier.michel@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Tom Lane @ 2022-12-13 18:49 UTC (permalink / raw)
  To: Michel Pelletier <pelletier.michel@gmail.com>; +Cc: pgsql-general

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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Is there a way to detect that code is inside CREATE EXTENSION?
  2022-12-13 18:39 Is there a way to detect that code is inside CREATE EXTENSION? Michel Pelletier <pelletier.michel@gmail.com>
  2022-12-13 18:49 ` Re: Is there a way to detect that code is inside CREATE EXTENSION? Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-12-13 18:58   ` Julien Rouhaud <rjuju123@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Julien Rouhaud @ 2022-12-13 18:58 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Michel Pelletier <pelletier.michel@gmail.com>; pgsql-general

On Tue, Dec 13, 2022 at 7:49 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> 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 ...

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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Is there a way to detect that code is inside CREATE EXTENSION?
  2022-12-13 18:39 Is there a way to detect that code is inside CREATE EXTENSION? Michel Pelletier <pelletier.michel@gmail.com>
  2022-12-13 18:49 ` Re: Is there a way to detect that code is inside CREATE EXTENSION? Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-12-13 18:59   ` Michel Pelletier <pelletier.michel@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Michel Pelletier @ 2022-12-13 18:59 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

>
> At the C-code level you can check the creating_extension global variable,
> or maybe better look at the in_extension fields of CollectedCommands.
>

Thanks Tom!

That was the hint I needed, looks like pg_event_trigger_ddl_commands() has
an in_extension boolean that seems like it will do what I need?   If I
understand you correctly that's what you're referring to with
CollectedCommands.   Testing it now but that looks like the answer for me,
if any of those are true then I can just skip the regeneration.

-Michel

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2022-12-13 18:59 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 18:39 Is there a way to detect that code is inside CREATE EXTENSION? Michel Pelletier <pelletier.michel@gmail.com>
2022-12-13 18:49 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-12-13 18:58   ` Julien Rouhaud <rjuju123@gmail.com>
2022-12-13 18:59   ` Michel Pelletier <pelletier.michel@gmail.com>

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