Movatterモバイル変換


[0]ホーム

URL:


November 13, 2025: PostgreSQL 18.1, 17.7, 16.11, 15.15, 14.20, and 13.23 Released!
DocumentationPostgreSQL devel (2025-12-17 20:34:52 - git commitab8af1db430)
Development Versions:devel
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for thecurrent version, or one of the other supported versions listed above instead.
44.6. Event Trigger Functions
Prev UpChapter 44. PL/Python — Python Procedural LanguageHome Next

44.6. Event Trigger Functions#

PL/Python can be used to define event triggers (see alsoChapter 38).PostgreSQL requires that a function that is to be called as an event trigger must be declared as a function with no arguments and a return type ofevent_trigger.

When a function is used as an event trigger, the dictionaryTD contains trigger-related values:

TD["event"]

The event the trigger was fired for, as a string, for exampleddl_command_start.

TD["tag"]

The command tag for which the trigger was fired, as a string, for exampleDROP TABLE.

Example 44.1 shows an example of an event trigger function inPL/Python.

Example 44.1. APL/Python Event Trigger Function

This example trigger simply raises aNOTICE message each time a supported command is executed.

CREATE OR REPLACE FUNCTION pysnitch() RETURNS event_triggerLANGUAGE plpython3uAS $$  plpy.notice("TD[event] => " + TD["event"] + " ; TD[tag] => " + TD["tag"]);$$;CREATE EVENT TRIGGER pysnitch ON ddl_command_start EXECUTE FUNCTION pysnitch();


Prev Up Next
44.5. Trigger Functions Home 44.7. Database Access

[8]ページ先頭

©2009-2025 Movatter.jp