Re: Setting global vars for use with triggers - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Setting global vars for use with triggers
Date
Msg-id 20050623000614.GA30804@winnie.fuhr.org
Whole thread Raw
In response to Setting global vars for use with triggers  (CSN <cool_screen_name90001@yahoo.com>)
List 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/

pgsql-general by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: multiple action rules
Next
From: Tom Lane
Date:
Subject: Re: Vacuum advice