pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedQuestion: what is proper way to define python function as event_trigger?
6+ messages / 3 participants
[nested] [flat]
* Question: what is proper way to define python function as event_trigger?
@ 2019-12-22 22:27 Andrei Pozolotin <andrei.pozolotin@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Andrei Pozolotin @ 2019-12-22 22:27 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hello.
Problem:
1. any attempt to define python function as an event_trigger, i.e.:
CREATE FUNCTION public.verify()
RETURNS event_trigger
LANGUAGE 'plpython3u'
AS $$ print("hello-kitty") $$;
2. fails with message:
ERROR: trigger functions can only be called as triggers
SQL state: 0A000
3. here in the source:
https://github.com/postgres/postgres/blob/master/src/pl/plpython/plpy_procedure.c#L226
Question:
what is proper way to define python function as event_trigger?
Thank you.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Question: what is proper way to define python function as event_trigger?
@ 2019-12-22 23:07 Jeff Ross <jross@openvistas.net>
parent: Andrei Pozolotin <andrei.pozolotin@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Jeff Ross @ 2019-12-22 23:07 UTC (permalink / raw)
To: Andrei Pozolotin <andrei.pozolotin@gmail.com>; pgsql-general@lists.postgresql.org
On 2019-12-22 15:27, Andrei Pozolotin wrote:
>
> Hello.
>
> Problem:
>
> 1. any attempt to define python function as an event_trigger, i.e.:
>
> CREATE FUNCTION public.verify()
> RETURNS event_trigger
> LANGUAGE 'plpython3u'
> AS $$ print("hello-kitty") $$;
>
> 2. fails with message:
>
> ERROR: trigger functions can only be called as triggers
>
> SQL state: 0A000
>
> 3. here in the source:
>
> https://github.com/postgres/postgres/blob/master/src/pl/plpython/plpy_procedure.c#L226
>
> Question:
>
> what is proper way to define python function as event_trigger?
>
> Thank you.
>
>
Just do
"create function public.verify() as trigger..."
https://www.postgresql.org/docs/10/plpython-trigger.html
TD["event"] contains the type of event as a string and I routinely do
things like
if TD["event"] == "UPDATE":
#do update stuff
elif TD["event'} == "INSERT":
#do insert related stuff
Jeff
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Question: what is proper way to define python function as event_trigger?
@ 2019-12-22 23:20 Jeff Ross <jross@openvistas.net>
parent: Jeff Ross <jross@openvistas.net>
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Ross @ 2019-12-22 23:20 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 2019-12-22 16:07, Jeff Ross wrote:
> On 2019-12-22 15:27, Andrei Pozolotin wrote:
>>
>> Hello.
>>
>> Problem:
>>
>> 1. any attempt to define python function as an event_trigger, i.e.:
>>
>> CREATE FUNCTION public.verify()
>> RETURNS event_trigger
>> LANGUAGE 'plpython3u'
>> AS $$ print("hello-kitty") $$;
>>
>> 2. fails with message:
>>
>> ERROR: trigger functions can only be called as triggers
>>
>> SQL state: 0A000
>>
>> 3. here in the source:
>>
>> https://github.com/postgres/postgres/blob/master/src/pl/plpython/plpy_procedure.c#L226
>>
>>
>> Question:
>>
>> what is proper way to define python function as event_trigger?
>>
>> Thank you.
>>
>>
> Just do
>
> "create function public.verify() as trigger..."
>
My bad--that should be "create function public.verify() returns trigger... "
Jeff
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Question: what is proper way to define python function as event_trigger?
@ 2019-12-22 23:40 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andrei Pozolotin <andrei.pozolotin@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Tom Lane @ 2019-12-22 23:40 UTC (permalink / raw)
To: Andrei Pozolotin <andrei.pozolotin@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
Andrei Pozolotin <andrei.pozolotin@gmail.com> writes:
> 1. any attempt to define python function as an event_trigger, i.e.:
AFAICS, there's not really any event trigger support in plpython.
That feature has only been built out in the other three PLs.
Somebody oughta fix this sometime, I guess, but it evidently hasn't
been high priority. If you feel like working on it, you could look
at commits e5dc4cc24d2e1e94ac572a2c64103710bf15d21e (for plperl)
and/or a5036ca998a6058f60913d43a80badfcbb65f5bb (for pltcl).
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Question: what is proper way to define python function as event_trigger?
@ 2019-12-23 02:52 Andrei Pozolotin <andrei.pozolotin@gmail.com>
parent: Jeff Ross <jross@openvistas.net>
0 siblings, 0 replies; 6+ messages in thread
From: Andrei Pozolotin @ 2019-12-23 02:52 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Jeff, hi:
1. my concern is global "event_trigger" for DDL, not per-table "trigger"
for DML
2. regardless - thank you for the link, I found it helpful
3. Tom Lane says event_trigger is just not implemented in plpython
Andrei.
On 2019-12-22 17:20, Jeff Ross wrote:
> On 2019-12-22 16:07, Jeff Ross wrote:
>> On 2019-12-22 15:27, Andrei Pozolotin wrote:
>>>
>>> Hello.
>>>
>>> Problem:
>>>
>>> 1. any attempt to define python function as an event_trigger, i.e.:
>>>
>>> CREATE FUNCTION public.verify()
>>> RETURNS event_trigger
>>> LANGUAGE 'plpython3u'
>>> AS $$ print("hello-kitty") $$;
>>>
>>> 2. fails with message:
>>>
>>> ERROR: trigger functions can only be called as triggers
>>>
>>> SQL state: 0A000
>>>
>>> 3. here in the source:
>>>
>>> https://github.com/postgres/postgres/blob/master/src/pl/plpython/plpy_procedure.c#L226
>>> Question:
>>>
>>> what is proper way to define python function as event_trigger?
>>>
>>> Thank you.
>>>
>>>
>> Just do
>>
>> "create function public.verify() as trigger..."
>>
> My bad--that should be "create function public.verify() returns
> trigger... "
>
> Jeff
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Question: what is proper way to define python function as event_trigger?
@ 2019-12-23 02:53 Andrei Pozolotin <andrei.pozolotin@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Andrei Pozolotin @ 2019-12-23 02:53 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Tom, hi:
1. actual use case has to do with:
BUG #16177: pg_event_trigger_ddl_commands() returns empty set for
ddl_command_start and "drop table"
https://www.postgresql.org/message-id/16177-053a34714817c3e1%40postgresql.org
2. I was merely hoping to re-implement pg_event_trigger_ddl_commands as
part of python event_trigger
3. do you think "pg_event_trigger_ddl_commands" is any easier to fix
then "support event_trigger in python"?
Thank you,
Andrei
On 2019-12-22 17:40, Tom Lane wrote:
> Andrei Pozolotin <andrei.pozolotin@gmail.com> writes:
>> 1. any attempt to define python function as an event_trigger, i.e.:
>
> AFAICS, there's not really any event trigger support in plpython.
> That feature has only been built out in the other three PLs.
>
> Somebody oughta fix this sometime, I guess, but it evidently hasn't
> been high priority. If you feel like working on it, you could look
> at commits e5dc4cc24d2e1e94ac572a2c64103710bf15d21e (for plperl)
> and/or a5036ca998a6058f60913d43a80badfcbb65f5bb (for pltcl).
>
> regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2019-12-23 02:53 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-12-22 22:27 Question: what is proper way to define python function as event_trigger? Andrei Pozolotin <andrei.pozolotin@gmail.com>
2019-12-22 23:07 ` Jeff Ross <jross@openvistas.net>
2019-12-22 23:20 ` Jeff Ross <jross@openvistas.net>
2019-12-23 02:52 ` Andrei Pozolotin <andrei.pozolotin@gmail.com>
2019-12-22 23:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-12-23 02:53 ` Andrei Pozolotin <andrei.pozolotin@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox