Re: [ADMIN] Notification - Mailing list pgsql-sql

From Jonathan Gardner
Subject Re: [ADMIN] Notification
Date
Msg-id 200306171334.24931.jgardner@jonathangardner.net
Whole thread Raw
List pgsql-sql
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 17 June 2003 05:13, Anagha Joshi wrote:
> Hi All,
> I'm new to Postgres. I'm using Postgres-7.2.4
> Can anybody guide me in detail how 'NOTIFY-LISTEN' can be implemented
> progmatically bet'n frontend and backend?
>

Might want to move this to the SQL list.

The idea is that a process will LISTEN for some notification. Another process
will NOTIFY that notification, and the one listening will get a message.

This is useful for a couple of things.

If you have an app that shows something like customer data, then you might
want to update the customer info when it changes.

Here's the table:
CREATE TABLE customer (    customer_id SERIAL PRIMARY KEY    , first_name VARCHAR(20) NOT NULL    , last_name
VARCHAR(20)NOT NULL); 

When displaying the customer info for customer_id 19291, you could do
something like:
LISTEN customer_19291;

Now when someone else goes in and changes the customer info in the database,
you can have a trigger set up that will NOTIFY.
CREATE OR REPLACE FUNCTION notify_on_update() RETURNS TRIGGER AS '    BEGIN    EXECUTE ''NOTIFY
''||TG_RELNAME||''_''||NEW.customer_id;   RETURN NEW;END' LANGUAGE 'plpgsql'; 
CREATE TRIGGER notify_on_update AFTER update ON customerFOR EACH ROW EXECUTE PROCEDURE notify_on_update();

Now you set up your application to watch for the notification. When it
receives the notification, if can update the displayed information.

Is this a good starting place?

- --
Jonathan Gardner <jgardner@jonathangardner.net>
(was jgardn@alumni.washington.edu)
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+73tPWgwF3QvpWNwRAqSQAKC/IsVy45bg4FAy4vwOK0PvBcfbjACg2XWT
D98xYLKLXVuQPkUGTiCVHVE=
=kpg2
-----END PGP SIGNATURE-----


pgsql-sql by date:

Previous
From: "Eric Anderson Vianet SAO"
Date:
Subject: Re: yet pg_toast reindex
Next
From: Rudi Starcevic
Date:
Subject: Re: Blobs with perl