summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/ref/unlisten.sgml
blob: 687bf485c9498e24e0d16a18d0637f76aa023ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!--
doc/src/sgml/ref/unlisten.sgml
PostgreSQL documentation
-->

<refentry id="sql-unlisten">
 <indexterm zone="sql-unlisten">
  <primary>UNLISTEN</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>UNLISTEN</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>UNLISTEN</refname>
  <refpurpose>stop listening for a notification</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
UNLISTEN { <replaceable class="parameter">channel</replaceable> | * }
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>UNLISTEN</command> is used to remove an existing
   registration for <command>NOTIFY</command> events.
   <command>UNLISTEN</command> cancels any existing registration of
   the current <productname>PostgreSQL</productname> session as a
   listener on the notification channel named <replaceable
   class="parameter">channel</replaceable>.  The special wildcard
   <literal>*</literal> cancels all listener registrations for the
   current session.
  </para>

  <para>
   <xref linkend="sql-notify"/>
   contains a more extensive
   discussion of the use of <command>LISTEN</command> and
   <command>NOTIFY</command>.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><replaceable class="parameter">channel</replaceable></term>
    <listitem>
     <para>
      Name of a notification channel (any identifier).
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>*</literal></term>
    <listitem>
     <para>
      All current listen registrations for this session are cleared.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Notes</title>

  <para>
   You can unlisten something you were not listening for; no warning or error
   will appear.
  </para>

  <para>
   At the end of each session, <command>UNLISTEN *</command> is
   automatically executed.
  </para>

  <para>
   A transaction that has executed <command>UNLISTEN</command> cannot be
   prepared for two-phase commit.
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   To make a registration:

<programlisting>
LISTEN virtual;
NOTIFY virtual;
Asynchronous notification "virtual" received from server process with PID 8448.
</programlisting>
  </para>

  <para>
   Once <command>UNLISTEN</command> has been executed, further <command>NOTIFY</command>
   messages will be ignored:

<programlisting>
UNLISTEN virtual;
NOTIFY virtual;
-- no NOTIFY event is received
</programlisting></para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   There is no <command>UNLISTEN</command> command in the SQL standard.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-listen"/></member>
   <member><xref linkend="sql-notify"/></member>
  </simplelist>
 </refsect1>
</refentry>