2
$PostgreSQL: pgsql/doc/src/sgml/ref/listen.sgml,v 1.21 2003-11-29 19:51:39 pgsql Exp $
3
PostgreSQL documentation
6
<refentry id="SQL-LISTEN">
8
<refentrytitle id="SQL-LISTEN-TITLE">LISTEN</refentrytitle>
9
<refmiscinfo>SQL - Language Statements</refmiscinfo>
13
<refname>LISTEN</refname>
14
<refpurpose>listen for a notification</refpurpose>
17
<indexterm zone="sql-listen">
18
<primary>LISTEN</primary>
23
LISTEN <replaceable class="PARAMETER">name</replaceable>
28
<title>Description</title>
31
<command>LISTEN</command> registers the current session as a
32
listener on the notification condition <replaceable
33
class="PARAMETER">name</replaceable>.
34
If the current session is already registered as a listener for
35
this notification condition, nothing is done.
39
Whenever the command <command>NOTIFY <replaceable
40
class="PARAMETER">name</replaceable></command> is invoked, either
41
by this session or another one connected to the same database, all
42
the sessions currently listening on that notification condition are
43
notified, and each will in turn notify its connected client
44
application. See the discussion of <command>NOTIFY</command> for
49
A session can be unregistered for a given notify condition with the
50
<command>UNLISTEN</command> command. A session's listen
51
registrations are automatically cleared when the session ends.
55
The method a client application must use to detect notification events depends on
56
which <productname>PostgreSQL</productname> application programming interface it
57
uses. With the <application>libpq</> library, the application issues
58
<command>LISTEN</command> as an ordinary SQL command, and then must
59
periodically call the function <function>PQnotifies</function> to find out
60
whether any notification events have been received. Other interfaces such as
61
<application>libpgtcl</> provide higher-level methods for handling notify events; indeed,
62
with <application>libpgtcl</> the application programmer should not even issue
63
<command>LISTEN</command> or <command>UNLISTEN</command> directly. See the
64
documentation for the interface you are using for more details.
68
<xref linkend="sql-notify" endterm="sql-notify-title">
69
contains a more extensive
70
discussion of the use of <command>LISTEN</command> and
71
<command>NOTIFY</command>.
76
<title>Parameters</title>
80
<term><replaceable class="PARAMETER">name</replaceable></term>
83
Name of a notify condition (any identifier).
91
<title>Examples</title>
94
Configure and execute a listen/notify sequence from
95
<application>psql</application>:
100
Asynchronous notification "virtual" received from server process with PID 8448.
106
<title>Compatibility</title>
109
There is no <command>LISTEN</command> statement in the SQL
115
<title>See Also</title>
117
<simplelist type="inline">
118
<member><xref linkend="sql-notify" endterm="sql-notify-title"></member>
119
<member><xref linkend="sql-unlisten" endterm="sql-unlisten-title"></member>
124
<!-- Keep this comment at the end of the file
129
sgml-minimize-attributes:nil
130
sgml-always-quote-attributes:t
133
sgml-parent-document:nil
134
sgml-default-dtd-file:"../reference.ced"
135
sgml-exposed-tags:nil
136
sgml-local-catalogs:"/usr/lib/sgml/catalog"
137
sgml-local-ecat-files:nil