blob: 93ca74c57222ae9ab3157a9a61e38acb6064c998 [file] [log] [blame]
$PostgreSQL: pgsql/doc/src/sgml/ref/listen.sgml,v 1.23 2008/11/14 10:22:47 petere Exp $
PostgreSQL documentation
<refentry id="SQL-LISTEN">
<refentrytitle id="SQL-LISTEN-TITLE">LISTEN</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
<refpurpose>listen for a notification</refpurpose>
<indexterm zone="sql-listen">
LISTEN <replaceable class="PARAMETER">name</replaceable>
<command>LISTEN</command> registers the current session as a
listener on the notification condition <replaceable
If the current session is already registered as a listener for
this notification condition, nothing is done.
Whenever the command <command>NOTIFY <replaceable
class="PARAMETER">name</replaceable></command> is invoked, either
by this session or another one connected to the same database, all
the sessions currently listening on that notification condition are
notified, and each will in turn notify its connected client
application. See the discussion of <command>NOTIFY</command> for
more information.
A session can be unregistered for a given notify condition with the
<command>UNLISTEN</command> command. A session's listen
registrations are automatically cleared when the session ends.
The method a client application must use to detect notification events depends on
which <productname>PostgreSQL</productname> application programming interface it
uses. With the <application>libpq</> library, the application issues
<command>LISTEN</command> as an ordinary SQL command, and then must
periodically call the function <function>PQnotifies</function> to find out
whether any notification events have been received. Other interfaces such as
<application>libpgtcl</> provide higher-level methods for handling notify events; indeed,
with <application>libpgtcl</> the application programmer should not even issue
<command>LISTEN</command> or <command>UNLISTEN</command> directly. See the
documentation for the interface you are using for more details.
<xref linkend="sql-notify" endterm="sql-notify-title">
contains a more extensive
discussion of the use of <command>LISTEN</command> and
<term><replaceable class="PARAMETER">name</replaceable></term>
Name of a notify condition (any identifier).
Configure and execute a listen/notify sequence from
LISTEN virtual;
NOTIFY virtual;
Asynchronous notification "virtual" received from server process with PID 8448.
There is no <command>LISTEN</command> statement in the SQL
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-notify" endterm="sql-notify-title"></member>
<member><xref linkend="sql-unlisten" endterm="sql-unlisten-title"></member>