Re: How to get a signal from the database when a INSERT INTO is done? - Mailing list pgsql-general

From Marti Raudsepp
Subject Re: How to get a signal from the database when a INSERT INTO is done?
Date
Msg-id CABRT9RAttybBYnsr-XPnPf2QHc7+yby7LHfhWjGc3Duch+cdRA@mail.gmail.com
Whole thread Raw
In response to How to get a signal from the database when a INSERT INTO is done?  (Andre Lopes <lopes80andre@gmail.com>)
Responses Re: How to get a signal from the database when a INSERT INTO is done?
List pgsql-general
On Tue, Feb 28, 2012 at 13:07, Andre Lopes <lopes80andre@gmail.com> wrote:
> This is a mixed question Python/PostgreSQL... I need to get a signal
> in my python application when a new insert is done. How can this be
> done, any clues?

As depesz mentioned, you can use the LISTEN and NOTIFY commands for
this asynchronous signalling. You can add an after-insert trigger to
send the NOTIFY.

On the Python end, you have to call psycopg2 connection.poll() method
periodically or in response to select() activation, and check the
connection.notifies list. Note that this list can grow even when you
run other queries -- not just on poll.

There's an example here:
http://initd.org/psycopg/docs/advanced.html#async-notify

Regards,
Marti

pgsql-general by date:

Previous
From: Clodoaldo Neto
Date:
Subject: Error installing postgresq91-python package
Next
From: Marti Raudsepp
Date:
Subject: Re: accumulating handles problem on machine running postgresql