Re: BUG #14815: event trigger in extension

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: gomer94(at)yandex(dot)ru
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14815: event trigger in extension
Date: 2017-09-16 19:52:15
Message-ID: 26965.1505591535@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

gomer94(at)yandex(dot)ru writes:
> I want to create extension with sql like:

> CREATE OR REPLACE FUNCTION keep_any_ddl_command() RETURNS event_trigger
> LANGUAGE plpgsql
> AS $$
> BEGIN
> SELECT classid, objid, objsubid FROM
> pg_event_trigger_ddl_commands();

> -- some insert code;
> END;
> $$;

> CREATE TABLE ddl_events();

> CREATE EVENT TRIGGER keep_all_ddl ON ddl_command_end
> EXECUTE PROCEDURE keep_any_ddl_command();

I think the reason this fails is that on the way out of the CREATE
EXTENSION command, the event trigger code sees that an event trigger
exists, so it tries to call it. But because no event trigger existed
when we started the CREATE EXTENSION command, the necessary
infrastructure hasn't been set up --- in particular,
EventTriggerBeginCompleteQuery did nothing at the time.

This seems like it would be an equal hazard for any situation where
CREATE EVENT TRIGGER is executed not at top level. Don't see an
easy fix right offhand.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander Scott 2017-09-16 20:42:40 Re: BUG #14817: pg_dumpall is not generating create database statements
Previous Message Tomas Vondra 2017-09-16 10:23:35 Re: Query planner skipping index depending on DISTINCT parameter order (2)