event trigger support for PL/Python

Lists: pgsql-hackers
From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: event trigger support for PL/Python
Date: 2025-07-16 12:01:37
Message-ID: 03f03515-2068-4f5b-b357-8fb540883c38@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

There is an old thread [1] that proposed $SUBJECT. That patch was not committed and the thread died. I use the referred patch as base for the attached version. The key differences between them are: documentation, tests, refactor (0001) and a few cleanups.

[1] https://www.postgresql.org/message-id/m2ob7wihex.fsf%402ndQuadrant.fr

--
Euler Taveira
EDB https://www.enterprisedb.com/

Attachment Content-Type Size
v1-0001-PL-Python-refactor-for-trigger-support.patch text/x-patch 6.9 KB
v1-0002-PL-Python-add-event-trigger-support.patch text/x-patch 10.3 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Euler Taveira <euler(at)eulerto(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-07-20 06:07:33
Message-ID: CAFj8pRB2CRwfE6wRoARbL50y3eW1j+hY7d4AvTFHCxJvrKbgyw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

it is registered in commitfest app?

The patch looks well

Regards

Pavel

st 16. 7. 2025 v 14:02 odesílatel Euler Taveira <euler(at)eulerto(dot)com> napsal:

> Hi,
>
> There is an old thread [1] that proposed $SUBJECT. That patch was not
> committed and the thread died. I use the referred patch as base for the
> attached version. The key differences between them are: documentation,
> tests, refactor (0001) and a few cleanups.
>
>
> [1] https://www.postgresql.org/message-id/m2ob7wihex.fsf%402ndQuadrant.fr
>
> --
> Euler Taveira
> EDB https://www.enterprisedb.com/


From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-07-29 12:52:37
Message-ID: c56def96-0524-4e7b-8b5b-3de5a9f3c40e@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jul 20, 2025, at 3:07 AM, Pavel Stehule wrote:
> it is registered in commitfest app?
>
> The patch looks well
>
Ops. I forgot to create one. I registered it now.

https://commitfest.postgresql.org/patch/5939/

--
Euler Taveira
EDB https://www.enterprisedb.com/


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Euler Taveira <euler(at)eulerto(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-07-29 14:18:42
Message-ID: CAFj8pRD2E1bd5C+JO-LZ43iPALJ7vAOnQVf9xc_+fmqp9Cje1g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

út 29. 7. 2025 v 14:53 odesílatel Euler Taveira <euler(at)eulerto(dot)com> napsal:

> On Sun, Jul 20, 2025, at 3:07 AM, Pavel Stehule wrote:
> > it is registered in commitfest app?
> >
> > The patch looks well
> >
> Ops. I forgot to create one. I registered it now.
>
> https://commitfest.postgresql.org/patch/5939/
>
>
Thank you

Pavel

>
> --
> Euler Taveira
> EDB https://www.enterprisedb.com/
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Euler Taveira <euler(at)eulerto(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-08-06 20:16:06
Message-ID: CAFj8pRA_LmSMt7SRXgu+eF=rWF71ANCkG_wFE_PyVu4a4xjb9A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi

út 29. 7. 2025 v 14:53 odesílatel Euler Taveira <euler(at)eulerto(dot)com> napsal:

> On Sun, Jul 20, 2025, at 3:07 AM, Pavel Stehule wrote:
> > it is registered in commitfest app?
> >
> > The patch looks well
> >
> Ops. I forgot to create one. I registered it now.
>
> https://commitfest.postgresql.org/patch/5939/
>
>
I am checking the code, and I don't like too much an introduction
of PLPyTrigType - more when it is used in
the pair with variable is_trigger. This combination looks strange and it is
a little bit difficult to read for me.

Maybe I prefer some like

typedef enum {
PLPY_CALLED_AS_TRIGGER,
PLPY_CALLED_AS_EVENT_TRIGGER,
PLPY_CALLED_AS_FUNCTION
} PLPyCallType;

and then instead

if (is_trigger == PLPY_NOT_TRIGGER)

the code can looks like

if (call_type == PLPY_CALLED_AS_FUNCTION)
{

}

What do you think?

Regards

Pavel

>
> --
> Euler Taveira
> EDB https://www.enterprisedb.com/
>


From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-08-07 00:34:58
Message-ID: a654c6d4-725c-4ae8-b349-e13a113d0df5@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 6, 2025, at 5:16 PM, Pavel Stehule wrote:
>
> I am checking the code, and I don't like too much an introduction of
> PLPyTrigType - more when it is used in
> the pair with variable is_trigger. This combination looks strange and
> it is a little bit difficult to read for me.
>
> Maybe I prefer some like
>
> typedef enum {
> PLPY_CALLED_AS_TRIGGER,
> PLPY_CALLED_AS_EVENT_TRIGGER,
> PLPY_CALLED_AS_FUNCTION
> } PLPyCallType;
>

I used the same pattern as PL/pgSQL

typedef enum PLpgSQL_trigtype
{
PLPGSQL_DML_TRIGGER,
PLPGSQL_EVENT_TRIGGER,
PLPGSQL_NOT_TRIGGER,
} PLpgSQL_trigtype;

Are you suggesting that we should modify it too?

> and then instead
>
> if (is_trigger == PLPY_NOT_TRIGGER)
>
> the code can looks like
>
> if (call_type == PLPY_CALLED_AS_FUNCTION)
> {
>
> }
>

The is_trigger variable is similar to fn_is_trigger in PL/pgSQL (see
PLpgSQL_function). If this variable is not clear maybe a prefix should avoid
confusion.

--
Euler Taveira
EDB https://www.enterprisedb.com/


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Euler Taveira <euler(at)eulerto(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-08-07 04:53:36
Message-ID: CAFj8pRBDX==ReHLtr4YacDRfBONA=HPRKB0arw82Tz78rmLBnA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

čt 7. 8. 2025 v 2:35 odesílatel Euler Taveira <euler(at)eulerto(dot)com> napsal:

> On Wed, Aug 6, 2025, at 5:16 PM, Pavel Stehule wrote:
> >
> > I am checking the code, and I don't like too much an introduction of
> > PLPyTrigType - more when it is used in
> > the pair with variable is_trigger. This combination looks strange and
> > it is a little bit difficult to read for me.
> >
> > Maybe I prefer some like
> >
> > typedef enum {
> > PLPY_CALLED_AS_TRIGGER,
> > PLPY_CALLED_AS_EVENT_TRIGGER,
> > PLPY_CALLED_AS_FUNCTION
> > } PLPyCallType;
> >
>
> I used the same pattern as PL/pgSQL
>

I see it

>
> typedef enum PLpgSQL_trigtype
> {
> PLPGSQL_DML_TRIGGER,
> PLPGSQL_EVENT_TRIGGER,
> PLPGSQL_NOT_TRIGGER,
> } PLpgSQL_trigtype;
>
> Are you suggesting that we should modify it too?
>

I am not happy about it, but maybe not, and it is a different issue. I
think fn_is_trigger is a little bit of a messy name too. It worked when
there was no other type of trigger and this variable was boolean. But the
rename breaks plpgsql plugins :-/, and I am not sure if it is an acceptable
cost. Although there are probably four plpgsql plugins, and the change can
be minimal and easy (and well detected)

Minimally - you should to use PLPY_DML_TRIGGER instead PLPY_TRIGGER

>
> > and then instead
> >
> > if (is_trigger == PLPY_NOT_TRIGGER)
> >
> > the code can looks like
> >
> > if (call_type == PLPY_CALLED_AS_FUNCTION)
> > {
> >
> > }
> >
>
> The is_trigger variable is similar to fn_is_trigger in PL/pgSQL (see
> PLpgSQL_function). If this variable is not clear maybe a prefix should
> avoid
> confusion.
>
>
Maybe the name "trigtype" can be better than "is_trigger". The similarity
with PLpgSQL has some benefits, but in this case I think so the plpgsql
design (of this case) is minimally confusing (and really the related part
in plpgsql_compile_callback can be cleaned). How much - this is a question.
There are two different things that are mixed together (and this is what I
dislike):

a) how the function was defined - RETURNS trigger, RETURNS event_trigger,
or something else

b) how the function was called - as dml trigger, as event trigger, or as
function or procedure

You can see, the event trigger has minimal intersection with the dml
trigger - but using the name "is_trigger" or "fn_is_trigger" implies
stronger relations between dml triggers and event triggers.

What do you think?

Regards

Pavel

>
> --
> Euler Taveira
> EDB https://www.enterprisedb.com/
>


From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-08-07 23:31:18
Message-ID: 4027d006-d045-433d-b679-9831803aff04@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Aug 7, 2025, at 1:53 AM, Pavel Stehule wrote:
> Minimally - you should to use PLPY_DML_TRIGGER instead PLPY_TRIGGER
>

I didn't use DML terminology for the same reason Peter said in another thread
[1]; let's *not* introduce a new terminology (DML trigger).

> Maybe the name "trigtype" can be better than "is_trigger". The
> similarity with PLpgSQL has some benefits, but in this case I think so
> the plpgsql design (of this case) is minimally confusing (and really
> the related part in plpgsql_compile_callback can be cleaned). How much
> - this is a question. There are two different things that are mixed
> together (and this is what I dislike):
>

I'm fine with trigger kind or trigger type but I wouldn't like to use DML
trigger.

[1] https://www.postgresql.org/message-id/1379995202.8103.4.camel@vanquo.pezone.net

--
Euler Taveira
EDB https://www.enterprisedb.com/


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Euler Taveira <euler(at)eulerto(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-08-08 05:04:34
Message-ID: CAFj8pRDgdnG2oQ8E431epguQkNS8g0kEtN2H1KyC9hZi9gzMfg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

pá 8. 8. 2025 v 1:31 odesílatel Euler Taveira <euler(at)eulerto(dot)com> napsal:

> On Thu, Aug 7, 2025, at 1:53 AM, Pavel Stehule wrote:
> > Minimally - you should to use PLPY_DML_TRIGGER instead PLPY_TRIGGER
> >
>
> I didn't use DML terminology for the same reason Peter said in another
> thread
> [1]; let's *not* introduce a new terminology (DML trigger).
>
> > Maybe the name "trigtype" can be better than "is_trigger". The
> > similarity with PLpgSQL has some benefits, but in this case I think so
> > the plpgsql design (of this case) is minimally confusing (and really
> > the related part in plpgsql_compile_callback can be cleaned). How much
> > - this is a question. There are two different things that are mixed
> > together (and this is what I dislike):
> >
>
> I'm fine with trigger kind or trigger type but I wouldn't like to use DML
> trigger.
>
>
> [1]
> https://www.postgresql.org/message-id/1379995202.8103.4.camel@vanquo.pezone.net

ok

Regards

Pavel

>
>
>
> --
> Euler Taveira
> EDB https://www.enterprisedb.com/
>


From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Euler Taveira <euler(at)eulerto(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-08-21 07:46:16
Message-ID: 4735d3fa-5bb3-4708-8a25-9f576d7486b1@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 16.07.25 14:01, Euler Taveira wrote:
> There is an old thread [1] that proposed $SUBJECT. That patch was not committed and the thread died. I use the referred patch as base for the attached version. The key differences between them are: documentation, tests, refactor (0001) and a few cleanups.

Committed.

I altered the documentation a bit to have the event triggers description
in its own sect1, next to normal triggers. This is how it's done in the
other PL chapters, so it made sense to keep it similar.


From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: "Peter Eisentraut" <peter(at)eisentraut(dot)org>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: event trigger support for PL/Python
Date: 2025-08-22 01:59:14
Message-ID: 5f583c31-62f5-4937-875d-285155de19ba@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Aug 21, 2025, at 4:46 AM, Peter Eisentraut wrote:
> On 16.07.25 14:01, Euler Taveira wrote:
>> There is an old thread [1] that proposed $SUBJECT. That patch was not committed and the thread died. I use the referred patch as base for the attached version. The key differences between them are: documentation, tests, refactor (0001) and a few cleanups.
>
> Committed.
>

Thanks.

> I altered the documentation a bit to have the event triggers description
> in its own sect1, next to normal triggers. This is how it's done in the
> other PL chapters, so it made sense to keep it similar.

LGTM.

--
Euler Taveira
EDB https://www.enterprisedb.com/