1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-31 05:54:36 +03:00

PL/Python: Add event trigger support

Allow event triggers to be written in PL/Python.  It provides a TD
dictionary with some information about the event trigger.

Author: Euler Taveira <euler@eulerto.com>
Co-authored-by: Dimitri Fontaine <dimitri@2ndQuadrant.fr>
Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/03f03515-2068-4f5b-b357-8fb540883c38%40app.fastmail.com
This commit is contained in:
Peter Eisentraut
2025-08-21 09:15:55 +02:00
parent 6e09c960eb
commit 53eff471c6
7 changed files with 182 additions and 0 deletions

View File

@@ -646,3 +646,30 @@ SELECT * FROM recursive_trigger_test;
1 | 2
(2 rows)
-- event triggers
CREATE OR REPLACE FUNCTION pysnitch() RETURNS event_trigger
LANGUAGE plpython3u
AS $$
plpy.notice("TD[event] => " + TD["event"] + " ; TD[tag] => " + TD["tag"]);
$$;
CREATE EVENT TRIGGER python_a_snitch ON ddl_command_start
EXECUTE PROCEDURE pysnitch();
CREATE EVENT TRIGGER python_b_snitch ON ddl_command_end
EXECUTE PROCEDURE pysnitch();
CREATE OR REPLACE FUNCTION foobar() RETURNS int LANGUAGE sql AS $$SELECT 1;$$;
NOTICE: TD[event] => ddl_command_start ; TD[tag] => CREATE FUNCTION
NOTICE: TD[event] => ddl_command_end ; TD[tag] => CREATE FUNCTION
ALTER FUNCTION foobar() COST 77;
NOTICE: TD[event] => ddl_command_start ; TD[tag] => ALTER FUNCTION
NOTICE: TD[event] => ddl_command_end ; TD[tag] => ALTER FUNCTION
DROP FUNCTION foobar();
NOTICE: TD[event] => ddl_command_start ; TD[tag] => DROP FUNCTION
NOTICE: TD[event] => ddl_command_end ; TD[tag] => DROP FUNCTION
CREATE TABLE foo();
NOTICE: TD[event] => ddl_command_start ; TD[tag] => CREATE TABLE
NOTICE: TD[event] => ddl_command_end ; TD[tag] => CREATE TABLE
DROP TABLE foo;
NOTICE: TD[event] => ddl_command_start ; TD[tag] => DROP TABLE
NOTICE: TD[event] => ddl_command_end ; TD[tag] => DROP TABLE
DROP EVENT TRIGGER python_a_snitch;
DROP EVENT TRIGGER python_b_snitch;