]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/pltcl-event-trigger.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / pltcl-event-trigger.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>42.7. Event Trigger Functions in PL/Tcl</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="pltcl-trigger.html" title="42.6. Trigger Functions in PL/Tcl" /><link rel="next" href="pltcl-error-handling.html" title="42.8. Error Handling in PL/Tcl" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">42.7. Event Trigger Functions in PL/Tcl</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="pltcl-trigger.html" title="42.6. Trigger Functions in PL/Tcl">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="pltcl.html" title="Chapter 42. PL/Tcl — Tcl Procedural Language">Up</a></td><th width="60%" align="center">Chapter 42. PL/Tcl — Tcl Procedural Language</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="pltcl-error-handling.html" title="42.8. Error Handling in PL/Tcl">Next</a></td></tr></table><hr /></div><div class="sect1" id="PLTCL-EVENT-TRIGGER"><div class="titlepage"><div><div><h2 class="title" style="clear: both">42.7. Event Trigger Functions in PL/Tcl <a href="#PLTCL-EVENT-TRIGGER" class="id_link">#</a></h2></div></div></div><a id="id-1.8.9.11.2" class="indexterm"></a><p>
3      Event trigger functions can be written in PL/Tcl.
4      <span class="productname">PostgreSQL</span> requires that a function that is
5      to be called as an event trigger must be declared as a function with no
6      arguments and a return type of <code class="literal">event_trigger</code>.
7     </p><p>
8      The information from the trigger manager is passed to the function body
9      in the following variables:
10
11      </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="varname">$TG_event</code></span></dt><dd><p>
12          The name of the event the trigger is fired for.
13         </p></dd><dt><span class="term"><code class="varname">$TG_tag</code></span></dt><dd><p>
14          The command tag for which the trigger is fired.
15         </p></dd></dl></div><p>
16     </p><p>
17      The return value of the trigger function is ignored.
18     </p><p>
19      Here's a little example event trigger function that simply raises
20      a <code class="literal">NOTICE</code> message each time a supported command is
21      executed:
22
23 </p><pre class="programlisting">
24 CREATE OR REPLACE FUNCTION tclsnitch() RETURNS event_trigger AS $$
25   elog NOTICE "tclsnitch: $TG_event $TG_tag"
26 $$ LANGUAGE pltcl;
27
28 CREATE EVENT TRIGGER tcl_a_snitch ON ddl_command_start EXECUTE FUNCTION tclsnitch();
29 </pre><p>
30     </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="pltcl-trigger.html" title="42.6. Trigger Functions in PL/Tcl">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pltcl.html" title="Chapter 42. PL/Tcl — Tcl Procedural Language">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pltcl-error-handling.html" title="42.8. Error Handling in PL/Tcl">Next</a></td></tr><tr><td width="40%" align="left" valign="top">42.6. Trigger Functions in PL/Tcl </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 42.8. Error Handling in PL/Tcl</td></tr></table></div></body></html>