Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/listen.sgml`
4735db28cfcd4e2ab2d64aa8aa5370f55f3bfc9506bcb4b300000001000009a9
<!--
doc/src/sgml/ref/listen.sgml
PostgreSQL documentation
-->

<refentry id="sql-listen">
 <indexterm zone="sql-listen">
  <primary>LISTEN</primary>
 </indexterm>

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

 <refnamediv>
  <refname>LISTEN</refname>
  <refpurpose>listen for a notification</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
LISTEN <replaceable class="parameter">channel</replaceable>
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>LISTEN</command> registers the current session as a
   listener on the notification channel named <replaceable
   class="parameter">channel</replaceable>.
   If the current session is already registered as a listener for
   this notification channel, nothing is done.
  </para>

  <para>
   Whenever the command <command>NOTIFY <replaceable
   class="parameter">channel</replaceable></command> is invoked, either
   by this session or another one connected to the same database, all
   the sessions currently listening on that notification channel are
   notified, and each will in turn notify its connected client
   application.
  </para>

  <para>
   A session can be unregistered for a given notification channel with the
   <command>UNLISTEN</command> command.  A session's listen
   registrations are automatically cleared when the session ends.
  </para>

  <para>
   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</application> 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</application> provide higher-level methods for handling notify events; indeed,
   with <application>libpgtcl</application> 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.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><replaceable class="parameter">channel</replaceable></term>

Title: LISTEN
Summary
The LISTEN command registers the current session as a listener on the specified notification channel. When a NOTIFY command is invoked on that channel, all listening sessions are notified, which in turn notify their connected client applications. Sessions can unregister with UNLISTEN, and all registrations are cleared when the session ends. The method a client uses to detect notifications depends on the PostgreSQL application programming interface.