44.7. Event Trigger Functions in PL/Tcl

|44.7. Event Trigger Functions in PL/Tcl|                |                                            |                  |                                  |
|:-------------------------------------:|----------------|--------------------------------------------|------------------|----------------------------------|
|      [Prev](pltcl-trigger.html)       |[Up](pltcl.html)|Chapter 44. PL/Tcl — Tcl Procedural Language|[Home](index.html)| [Next](pltcl-error-handling.html)|

---

## 44.7. Event Trigger Functions in PL/Tcl

[]()

 Event trigger functions can be written in PL/Tcl. 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 of `event_trigger`.

 The information from the trigger manager is passed to the function body in the following variables:

`$TG_event`

 The name of the event the trigger is fired for.

`$TG_tag`

 The command tag for which the trigger is fired.

 The return value of the trigger function is ignored.

 Here's a little example event trigger function that simply raises a `NOTICE` message each time a supported command is executed:

```
CREATE OR REPLACE FUNCTION tclsnitch() RETURNS event_trigger AS $$
  elog NOTICE "tclsnitch: $TG_event $TG_tag"
$$ LANGUAGE pltcl;

CREATE EVENT TRIGGER tcl_a_snitch ON ddl_command_start EXECUTE FUNCTION tclsnitch();

```

---

|   [Prev](pltcl-trigger.html)    | [Up](pltcl.html) | [Next](pltcl-error-handling.html)|
|:--------------------------------|:----------------:|---------------------------------:|
|44.6. Trigger Functions in PL/Tcl|[Home](index.html)|  44.8. Error Handling in PL/Tcl  |

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>