Re: Setting global vars for use with triggers

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Setting global vars for use with triggers
Date: 2005-06-23 00:06:14
Message-ID: 20050623000614.GA30804@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 22, 2005 at 01:36:20PM -0700, CSN wrote:
>
> I'd like to create a trigger which deletes associated
> files whenever their corresponding row is deleted.

I looked at the thread you posted and saw that you were considering
using LISTEN/NOTIFY. That's probably a good idea because if you
delete a file in a trigger, you don't have a way to undelete it if
the transaction rolls back. If you use NOTIFY then the notification
should be delivered to the listener only if the transaction commits.

Ideally the listener wouldn't repeatedly sleep and check for
notifications -- you'd use a function like select() or poll() in C
(socket_select() in PHP) that would tell you immediately when data
is available on the database connection's socket (and only then).
Unfortunately I don't see a way for the PHP PostgreSQL interface
to get the connection's file descriptor as you would in C with
PQsocket(). If you use PHP then you might be stuck with sleep/check,
so you might want to consider writing the listener in another
language.

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-06-23 00:46:52 Re: Vacuum advice
Previous Message Scott Marlowe 2005-06-22 23:45:36 Re: multiple action rules