Perl trigger not working

From: Jignesh Shah <jignesh(dot)shah1980(at)gmail(dot)com>
To: postgresql novice <pgsql-novice(at)postgresql(dot)org>
Subject: Perl trigger not working
Date: 2009-08-26 14:52:42
Message-ID: c11950270908260752j398d7249g631cbe4c3a46a7c9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have taken ditto perl trigger example from PostgreSQL documentation
Chapter 40 (
http://developer.postgresql.org/pgdocs/postgres/plperl-triggers.html) and
installed on my database but it not printing anything and also not inserting
any rows in "test" table. See below. Please help me out with it. What I am
doing wrong?

mydb=# CREATE TABLE test (
mydb(# i int,
mydb(# v varchar
mydb(# );
CREATE TABLE
mydb=# CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS $$
mydb$# if (($_TD->{new}{i} >= 100) || ($_TD->{new}{i} <= 0)) {
mydb$# return "SKIP"; # skip INSERT/UPDATE command
mydb$# } elsif ($_TD->{new}{v} ne "immortal") {
mydb$# $_TD->{new}{v} .= "(modified by trigger)";
mydb$# return "MODIFY"; # modify row and execute INSERT/UPDATE command
mydb$# } else {
mydb$# return; # execute INSERT/UPDATE command
mydb$# }
mydb$# $$ LANGUAGE plperl;
CREATE FUNCTION
mydb=# CREATE TRIGGER test_valid_id_trig
mydb-# BEFORE INSERT OR UPDATE ON test
mydb-# FOR EACH ROW EXECUTE PROCEDURE valid_id();
CREATE TRIGGER
mydb=# insert INTO test VALUES(100, 'c');
INSERT 0 0
mydb=# insert INTO test VALUES(200, 'c');
INSERT 0 0
mydb=# select * from test;

mydb=#
Thanks,
Jignesh

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Ibrahim Shaame 2009-08-26 15:38:51 how to install postgresql on windows without admin privileges
Previous Message Jignesh Shah 2009-08-26 14:42:10 Re: Install new perl test function in PostgreSQL