.\\" auto-generated by docbook2man-spec $Revision: 1.25 $ .TH "LISTEN" "7" "2002-11-22" "SQL - Language Statements" "SQL Commands" .SH NAME LISTEN \- listen for a notification .SH SYNOPSIS .sp .nf LISTEN \fIname\fR .sp .fi .SS "INPUTS" .PP .TP \fB\fIname\fB\fR Name of notify condition. .PP .SS "OUTPUTS" .PP .TP \fBLISTEN\fR Message returned upon successful completion of registration. .TP \fBWARNING: Async_Listen: We are already listening on \fIname\fB\fR If this backend is already registered for that notify condition. .PP .SH "DESCRIPTION" .PP \fBLISTEN\fR registers the current PostgreSQL backend as a listener on the notify condition \fIname\fR. .PP Whenever the command \fBNOTIFY \fIname\fB\fR is invoked, either by this backend or another one connected to the same database, all the backends currently listening on that notify condition are notified, and each will in turn notify its connected frontend application. See the discussion of \fBNOTIFY\fR for more information. .PP A backend can be unregistered for a given notify condition with the \fBUNLISTEN\fR command. Also, a backend's listen registrations are automatically cleared when the backend process exits. .PP The method a frontend application must use to detect notify events depends on which PostgreSQL application programming interface it uses. With the \fBlibpq\fR library, the application issues \fBLISTEN\fR as an ordinary SQL command, and then must periodically call the routine \fBPQnotifies\fR to find out whether any notify events have been received. Other interfaces such as \fBlibpgtcl\fR provide higher-level methods for handling notify events; indeed, with \fBlibpgtcl\fR the application programmer should not even issue \fBLISTEN\fR or \fBUNLISTEN\fR directly. See the documentation for the library you are using for more details. .PP NOTIFY [\fBnotify\fR(7)] contains a more extensive discussion of the use of \fBLISTEN\fR and \fBNOTIFY\fR. .SS "NOTES" .PP \fIname\fR can be any string valid as a name; it need not correspond to the name of any actual table. If \fInotifyname\fR is enclosed in double-quotes, it need not even be a syntactically valid name, but can be any string up to 63 characters long. .PP In some previous releases of PostgreSQL, \fIname\fR had to be enclosed in double-quotes when it did not correspond to any existing table name, even if syntactically valid as a name. That is no longer required. .SH "USAGE" .PP Configure and execute a listen/notify sequence from \fBpsql\fR: .sp .nf LISTEN virtual; NOTIFY virtual; Asynchronous NOTIFY 'virtual' from backend with pid '8448' received. .sp .fi .SH "COMPATIBILITY" .SS "SQL92" .PP There is no \fBLISTEN\fR in SQL92.