40.4. A Complete Event Trigger Example
Here is a very simple example of an event trigger function written in C. (Examples of triggers written in procedural languages can be found in the documentation of the procedural languages.)
The function noddl
raises an exception each time it is called. The event trigger definition associated the function with the ddl_command_start
event. The effect is that all DDL commands (with the exceptions mentioned in Section 40.1) are prevented from running.
This is the source code of the trigger function:
After you have compiled the source code (see Section 38.10.5), declare the function and the triggers:
Now you can test the operation of the trigger:
In this situation, in order to be able to run some DDL commands when you need to do so, you have to either drop the event trigger or disable it. It can be convenient to disable the trigger for only the duration of a transaction:
(Recall that DDL commands on event triggers themselves are not affected by event triggers.)