LISTEN

Name

LISTEN — Listen for notification on a relation
LISTEN classname

Inputs

classname

Table object used for notification.

Outputs

LISTEN

Message returned upon successful completion of registration.

Description

LISTEN is used to register the current backend as a listener on the relation classname. When the command NOTIFY classname is called either from within a rule or at the query level, the frontend applications corresponding to the listening backends are notified. When the backend process exits, this registration is cleared.

This event notification is performed through the libpq protocol and frontend application interface. The application program must call the routine PQnotifies in order to find out the name of the class to which a given notification corresponds. If this code is not included in the application, the event notification will be queued and never be processed.

Notes

Note that classname needs not to be a valid class name but can be any string valid as a name up to 32 characters long.

A restriction in some previous releases of Postgres that a classname which does not correspond to an actual table must be enclosed in double-quotes is no longer present.

Usage

postgres=> listen virtual;
LISTEN
postgres=> notify virtual;
NOTIFY
ASYNC NOTIFY of 'virtual' from backend pid '11239' received

Compatibility

SQL92

There is no LISTEN statement in SQL92.