Обсуждение: Is it possible to use an EVENT TRIGGER to validate a TRIGGER?

Поиск
Список
Период
Сортировка

Is it possible to use an EVENT TRIGGER to validate a TRIGGER?

От
Luís Eduardo Oliveira Lizardo
Дата:
Hi,

Is it possible to use an EVENT TRIGGER to validate a TRIGGER definition?

What I want is to guarantee that the trigger is fired AFTER a STATEMENT, on INSERT or UPDATE but not on DELETE, like the following example:


CREATE TRIGGER mytrigger  AFTER INSERT OR UPDATE ON mytable  FOR EACH STATEMENT  EXECUTE PROCEDURE myprocedure();

I know I can check those parameters inside the trigger function with TG_OP, TG_WHEN and TG_LEVEL, but in this way, it only checks if the trigger is correct during an insertion, upload or deletion, and not right after the trigger definition.

Best regards,

Luis Lizardo

Re: Is it possible to use an EVENT TRIGGER to validate a TRIGGER?

От
Alvaro Herrera
Дата:
Luís Eduardo Oliveira Lizardo wrote:
> Hi,
>
> Is it possible to use an EVENT TRIGGER to validate a TRIGGER definition?
>
> What I want is to guarantee that the trigger is fired AFTER a STATEMENT, on
> INSERT or UPDATE but not on DELETE, like the following example:

What you can do with a C language function in 9.5 is to examine the
CreateTrigger struct and verify that it matches the conditions you want.
So, yes, it's possible, but not in plpgsql.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Re: Is it possible to use an EVENT TRIGGER to validate a TRIGGER?

От
Luís Eduardo Oliveira Lizardo
Дата:

Hi Álvaro, thanks for your reaponse.

Can you please give me a small example showing how to do this, or more hints?

Thanks in advance,

Luis Lizardo

On Jul 6, 2016 00:02, "Alvaro Herrera" <alvherre@2ndquadrant.com> wrote:
Luís Eduardo Oliveira Lizardo wrote:
> Hi,
>
> Is it possible to use an EVENT TRIGGER to validate a TRIGGER definition?
>
> What I want is to guarantee that the trigger is fired AFTER a STATEMENT, on
> INSERT or UPDATE but not on DELETE, like the following example:

What you can do with a C language function in 9.5 is to examine the
CreateTrigger struct and verify that it matches the conditions you want.
So, yes, it's possible, but not in plpgsql.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services