Re: Is there a way to be notified on the CREATE TABLE execution?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Igor Korot <ikorot01(at)gmail(dot)com>, Francisco Olarte <folarte(at)peoplecall(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Is there a way to be notified on the CREATE TABLE execution?
Date: 2018-06-20 20:16:44
Message-ID: CAKFQuwYy4YwXX0XWXiUCyHJscXZ9wsmvMbsxgZQ=mRTTHvEzsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 20, 2018 at 1:02 PM, Alvaro Herrera <alvherre(at)2ndquadrant(dot)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.

[1]
https://www.postgresql.org/docs/10/static/plpgsql-overview.html#PLPGSQL-ARGS-RESULTS

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrien Nayrat 2018-06-20 21:02:39 Re: Suggestion about logging only every n-th statement
Previous Message Mukesh Chhatani 2018-06-20 20:13:24 Re: Postgres 10.4 crashing when using PLV8