@@ -10,20 +10,20 @@ LISTEN
10
10
LISTEN
11
11
</REFNAME>
12
12
<REFPURPOSE>
13
- Listen for notification on a relation
13
+ Listen for notification on a notify condition
14
14
</REFPURPOSE>
15
15
16
16
<REFSYNOPSISDIV>
17
17
<REFSYNOPSISDIVINFO>
18
- <DATE>1998-09-24 </DATE>
18
+ <DATE>1998-10-07 </DATE>
19
19
</REFSYNOPSISDIVINFO>
20
20
<SYNOPSIS>
21
- LISTEN <REPLACEABLE CLASS="PARAMETER">classname </REPLACEABLE>
21
+ LISTEN <REPLACEABLE CLASS="PARAMETER">notifyname </REPLACEABLE>
22
22
</SYNOPSIS>
23
23
24
24
<REFSECT2 ID="R2-SQL-LISTEN-1">
25
25
<REFSECT2INFO>
26
- <DATE>1998-09-01 </DATE>
26
+ <DATE>1998-10-07 </DATE>
27
27
</REFSECT2INFO>
28
28
<TITLE>
29
29
Inputs
@@ -33,11 +33,11 @@ Inputs
33
33
<VARIABLELIST>
34
34
<VARLISTENTRY>
35
35
<TERM>
36
- <REPLACEABLE CLASS="PARAMETER">classname </REPLACEABLE>
36
+ <REPLACEABLE CLASS="PARAMETER">notifyname </REPLACEABLE>
37
37
</TERM>
38
38
<LISTITEM>
39
39
<PARA>
40
- Table object used for notification .
40
+ Name of notify condition .
41
41
42
42
</VARIABLELIST>
43
43
@@ -62,63 +62,95 @@ Outputs
62
62
<VARIABLELIST>
63
63
<VARLISTENTRY>
64
64
<TERM>
65
- LISTEN
65
+ <returnvalue> LISTEN</returnvalue>
66
66
</TERM>
67
67
<LISTITEM>
68
68
<PARA>
69
69
Message returned upon successful completion of registration.
70
-
71
- </VARIABLELIST>
70
+ </PARA>
71
+ </LISTITEM>
72
+ </VARLISTENTRY>
73
+ <VARLISTENTRY>
74
+ <TERM>
75
+ <returnvalue>NOTICE Async_Listen: We are already listening on notifyname</returnvalue>
76
+ </TERM>
77
+ <LISTITEM>
78
+ <PARA>
79
+ If this backend is already registered for that notify condition.
80
+ </PARA>
81
+ </LISTITEM>
82
+ </VARLISTENTRY>
83
+ </variablelist>
84
+ </LISTITEM>
85
+ </VARLISTENTRY>
72
86
</VARIABLELIST>
73
-
74
87
</REFSECT2>
75
88
</REFSYNOPSISDIV>
76
89
77
90
<REFSECT1 ID="R1-SQL-LISTEN-1">
78
91
<REFSECT1INFO>
79
- <DATE>1998-09-24 </DATE>
92
+ <DATE>1998-10-07 </DATE>
80
93
</REFSECT1INFO>
81
94
<TITLE>
82
95
Description
83
96
</TITLE>
84
97
<PARA>
85
- LISTEN is used to register the current backend as a listener on the relation
86
- <REPLACEABLE CLASS="PARAMETER">classname</REPLACEABLE>.
87
- When the command
88
- <command>NOTIFY <REPLACEABLE CLASS="PARAMETER">classname</REPLACEABLE></command>
89
- is called either from within a rule or at the query level, the
90
- frontend applications corresponding to the listening backends
91
- are notified. When the backend process exits, this registration
92
- is cleared.
98
+ LISTEN registers the current <productname>Postgres</productname> backend as a
99
+ listener on the notify condition
100
+ <REPLACEABLE CLASS="PARAMETER">notifyname</REPLACEABLE>.
101
+
102
+ <para>
103
+ Whenever the command
104
+ <command>NOTIFY <REPLACEABLE CLASS="PARAMETER">notifyname</REPLACEABLE></command>
105
+ is invoked, either by this backend or another one connected to
106
+ the same database, all the backends currently listening on that notify
107
+ condition are notified, and each will in turn notify its connected
108
+ frontend application. See the discussion of <command>NOTIFY</command>
109
+ for more information.
93
110
94
111
<para>
95
- This event notification is performed through the libpq protocol
96
- and frontend application interface. The application program
97
- must call the routine
98
- <function>PQnotifies</function>
99
- in order to find out the name of the class to which a given
100
- notification corresponds. If this code is not included in
101
- the application, the event notification will be queued and
102
- never be processed.
112
+ A backend can be deregistered for a given notify condition with the
113
+ <command>UNLISTEN</command> command. Also, a backend's listen registrations
114
+ are automatically cleared when the backend process exits.
115
+
116
+ <para>
117
+ The method a frontend application must use to detect notify events depends on
118
+ which <productname>Postgres</productname> application programming interface it
119
+ uses. With the basic libpq library, the application issues
120
+ <command>LISTEN</command> as an ordinary SQL command, and then must
121
+ periodically call the routine <function>PQnotifies</function> to find out
122
+ whether any notify events have been received. Other interfaces such as
123
+ libpgtcl provide higher-level methods for handling notify events; indeed,
124
+ with libpgtcl the application programmer should not even issue
125
+ <command>LISTEN</command> or <command>UNLISTEN</command> directly. See the
126
+ documentation for the library you are using for more details.
127
+
128
+ <para>
129
+ The reference page for <command>NOTIFY</command> contains a more extensive
130
+ discussion of the use of <command>LISTEN</command> and
131
+ <command>NOTIFY</command>.
103
132
104
133
<REFSECT2 ID="R2-SQL-LISTEN-3">
105
134
<REFSECT2INFO>
106
- <DATE>1998-09-24 </DATE>
135
+ <DATE>1998-10-07 </DATE>
107
136
</REFSECT2INFO>
108
137
<TITLE>
109
138
Notes
110
139
</TITLE>
111
140
<para>
112
- Note that <REPLACEABLE CLASS="PARAMETER">classname</REPLACEABLE>
113
- needs not to be a valid class name but can be any string valid
114
- as a name up to 32 characters long.
141
+ <REPLACEABLE CLASS="PARAMETER">notifyname</REPLACEABLE>
142
+ can be any string valid as a name;
143
+ it need not correspond to the name of any actual table. If
144
+ <REPLACEABLE CLASS="PARAMETER">notifyname</REPLACEABLE>
145
+ is enclosed in double-quotes, it need not even be a syntactically
146
+ valid name, but can be any string up to 31 characters long.
115
147
116
148
<para>
117
- A restriction in some previous releases of
118
- <productname>Postgres</productname> that a
119
- <REPLACEABLE CLASS="PARAMETER">classname </REPLACEABLE>
120
- which does not correspond to an actual table must be enclosed in double-quotes
121
- is no longer present .
149
+ In some previous releases of
150
+ <productname>Postgres</productname>,
151
+ <REPLACEABLE CLASS="PARAMETER">notifyname </REPLACEABLE>
152
+ had to be enclosed in double-quotes when it did not correspond to any existing
153
+ table name, even if syntactically valid as a name. That is no longer required .
122
154
123
155
</REFSECT2>
124
156
@@ -128,6 +160,7 @@ Usage
128
160
</TITLE>
129
161
<PARA>
130
162
<ProgramListing>
163
+ -- Configure and execute a listen/notify sequence from psql
131
164
postgres=> listen virtual;
132
165
LISTEN
133
166
postgres=> notify virtual;
0 commit comments