Re: Is there a way to be notified on the CREATE TABLE execution? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Is there a way to be notified on the CREATE TABLE execution?
Date
Msg-id CAKFQuwYy4YwXX0XWXiUCyHJscXZ9wsmvMbsxgZQ=mRTTHvEzsA@mail.gmail.com
Whole thread Raw
In response to Re: Is there a way to be notified on the CREATE TABLE execution?  (Igor Korot <ikorot01@gmail.com>)
List pgsql-general
On Wed, Jun 20, 2018 at 1:02 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
On 2018-Jun-20, Igor Korot wrote:

> [quote]
> In order to create an event trigger, you must first create a function
> with the special return type event_trigger. This function need not
> (and may not) return a value; the return type serves merely as a
> signal that the function is to be invoked as an event trigger.
> [/quote]
>
> So, the function has to be created and compiled.

​The section talking about C-language event triggers leads with:​

​"""
This section describes the low-level details of the interface to an event trigger function. This information is only needed when writing event trigger functions in C. If you are using a higher-level language then these details are handled for you. In most cases you should consider using a procedural language before writing your event triggers in C. The documentation of each procedural language explains how to write an event trigger in that language. 
"""  ​

​In short, I agree that cursory reading of the main event trigger chapter could ​lead one to conclude that they are implemented in "C"; but all of the relevant information is available in the docs and correctly pointed too and accessible if one reads carefully or looks for it explicitly.  I don't see how it can be much improved simply and there doesn't seem to be enough confusion (or use) to warrant significant effort in that area.


Event trigger functions can be written in plpgsql.  You can use
pg_event_trigger_ddl_commands() in the ddl_command_end event to obtain a
few tidbits about the DDL that was just executed.

​There are a number of examples of a pl/pgsql function returning an "event_trigger" ​pseudo-type: but I cannot locate an official statement that doing so is valid.  I was expecting a paragraph at [1] but it is not there.  Adding one and linking it to the overall event trigger chapter as well as the event trigger section of the pl/pgsql chapter seems warranted.



David J.

pgsql-general by date:

Previous
From: Mukesh Chhatani
Date:
Subject: Re: Postgres 10.4 crashing when using PLV8
Next
From: Adrien Nayrat
Date:
Subject: Re: Suggestion about logging only every n-th statement