Writing PL/Perl triggers

If you want to write trigger functions using Perl, then PL/Perl allows you to do all the good stuff that you have learned so far using PL/PgSQL. Let's rewrite an example we demonstrated in Chapter 5, PL/pgSQL Trigger Functions, in PL/Perl. Recall the simple, "Hey, I am called" trigger. The PL/Perl version of the example looks as shown in the following code. We probably don't need to provide a more complex example, as this simple example demonstrates the PL/Perl syntax in a sufficient way:

CREATE OR REPLACE FUNCTION notify_trigger_plperl() RETURNS TRIGGER AS $$ $result = sprintf('Hi, I got %s invoked FOR %s %s %s on %s', $_TD->{name}, $_TD->{level}, $_TD->{when}, $_TD->{event}, $_TD->{table_name} ); if(($_TD->{event} cmp ...

Get PostgreSQL Server Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.