45.7. PL/Perl Event Triggers

|45.7. PL/Perl Event Triggers|                 |                                              |                  |                                   |
|:--------------------------:|-----------------|----------------------------------------------|------------------|-----------------------------------|
|[Prev](plperl-triggers.html)|[Up](plperl.html)|Chapter 45. PL/Perl — Perl Procedural Language|[Home](index.html)| [Next](plperl-under-the-hood.html)|

---

## 45.7. PL/Perl Event Triggers

 PL/Perl can be used to write event trigger functions. In an event trigger function, the hash reference `$_TD` contains information about the current trigger event. `$_TD` is a global variable, which gets a separate local value for each invocation of the trigger. The fields of the `$_TD` hash reference are:

`$_TD->{event}`

 The name of the event the trigger is fired for.

`$_TD->{tag}`

 The command tag for which the trigger is fired.

 The return value of the trigger function is ignored.

 Here is an example of an event trigger function, illustrating some of the above:

```
CREATE OR REPLACE FUNCTION perlsnitch() RETURNS event_trigger AS $$
  elog(NOTICE, "perlsnitch: " . $_TD->{event} . " " . $_TD->{tag} . " ");
$$ LANGUAGE plperl;

CREATE EVENT TRIGGER perl_a_snitch
    ON ddl_command_start
    EXECUTE FUNCTION perlsnitch();

```

---

|[Prev](plperl-triggers.html)|[Up](plperl.html) | [Next](plperl-under-the-hood.html)|
|:---------------------------|:----------------:|----------------------------------:|
|   45.6. PL/Perl Triggers   |[Home](index.html)|    45.8. PL/Perl Under the Hood   |

 // \<![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.'); })(); } // ]]\>