Re: Problems with trigger and function.

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Ville Leinonen <ville(dot)leinonen(at)megata(dot)vu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Problems with trigger and function.
Date: 2005-06-13 14:10:00
Message-ID: 20050613141000.GA81995@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, Jun 13, 2005 at 02:15:17PM +0300, Ville Leinonen wrote:
>
> Id like to to function with plperlu which write's db-events to log-file.

What version of PostgreSQL are you using? PL/Perl trigger functions
are supported only in 8.0 and later.

> My trigger looks like this:
>
> CREATE TRIGGER trapd
> BEFORE INSERT OR UPDATE ON events FOR EACH ROW
> EXECUTE PROCEDURE write_trapd();
>
> But now i have a problem how to write that event information for specific
> file. I dont want to write whole event, only part offit.

It's not clear what you're having trouble with. Getting the event
info? If so then see the documentation for the $_TD hash reference:

http://www.postgresql.org/docs/8.0/static/plperl-triggers.html

If something else then please be more specific.

> My goal is to read that log file (eg. tail) and when there comes new event
> some other programs executes some other programs.

That might not be the best design because the log file won't have
transaction semantics. Suppose you update the table and write a
message to the log file, then some other program reads the log file
and does something based on the update, then you roll back the
update. Now you've done something based on an update that effectively
didn't happen. You might wish to consider using NOTIFY and LISTEN
if you want to do event notification.

http://www.postgresql.org/docs/8.0/static/sql-notify.html
http://www.postgresql.org/docs/8.0/static/sql-listen.html
http://www.postgresql.org/docs/8.0/static/libpq-notify.html

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2005-06-13 14:21:24 Re: Steps taken through while transmitting binary data
Previous Message János 2005-06-13 13:25:30 Re: need suggestion for server sizing