Include cross-references in NOTIFY and UNLISTEN.
to get a new number from the sequence.
The function
<function>currval('<replaceable class="parameter">seqname</replaceable>')</function>
- may be used
- to determine the number returned by the last call to
+ may be used to determine the number returned by the last call to
<function>nextval(<replaceable class="parameter">seqname</replaceable>)</function>
for the specified sequence in the current session.
+The function
+<function>setval('<replaceable class="parameter">seqname</replaceable>',
+ <replaceable class="parameter">newvalue</replaceable>)</function>
+may be used to set the current value of the specified sequence.
+The next call to
+<function>nextval(<replaceable class="parameter">seqname</replaceable>)</function>
+will return the given value plus the sequence increment.
</para>
<para>
calls to a generator.
</para>
- <para>
- <TITLE>
- NOTE:
- </TITLE>
+<caution>
+<para>
Unexpected results may be obtained if a cache setting greater than one
is used for a sequence object that will be used concurrently by multiple
backends. Each backend will allocate "cache" successive sequence values
will be lost. Furthermore, although multiple backends are guaranteed to
allocate distinct sequence values, the values may be generated out of
sequence when all the backends are considered. (For example, with a cache
- setting of 10, backend A might reserve values 1..10 and return nextval=1, then
+ setting of 10, backend A might reserve values 1..10 and return nextval=1,
+then
backend B might reserve values 11..20 and return nextval=11 before backend
A has generated nextval=2.) Thus, with a cache setting of one it is safe
to assume that nextval values are generated sequentially; with a cache
are all distinct, not that they are generated purely sequentially.
Also, last_value will reflect the latest value reserved by any backend,
whether or not it has yet been returned by nextval.
- </para>
+</caution>
<REFSECT2 ID="R2-SQL-CREATESEQUENCE-3">
<REFSECT2INFO>
INSERT INTO distributors VALUES (NEXTVAL('serial'),'nothing');
</programlisting>
</para>
+
+ <para>
+ Set the sequence value after a COPY FROM:
+ <programlisting>
+CREATE FUNCTION distributors_id_max() RETURNS INT4
+ AS 'SELECT max(id) FROM distributors'
+ LANGUAGE 'sql';
+BEGIN;
+COPY distributors FROM 'input_file';
+SELECT setval('serial', distributors_id_max());
+END;
+ </programlisting>
+ </para>
+
</REFSECT1>
<REFSECT1 ID="R1-SQL-CREATESEQUENCE-3">
an insert or update operation to succeed. Each constraint
must evaluate to a boolean expression. Multiple columns
may be referenced within a single constraint.
- The use of
- <TERM>
+ Only one PRIMARY KEY clause may be specified for a table;
PRIMARY KEY <REPLACEABLE>column</REPLACEABLE>
- </TERM>
- as a table constraint
- is mutually incompatible with
- <TERM>
- PRIMARY KEY
- </TERM>
- used as a column constraint.
+ (a table constraint) and PRIMARY KEY (a column constraint) are
+ mutually exclusive..
See the table constraint clause for more information.
</PARA>
</LISTITEM>
<REFENTRY ID="SQL-NOTIFY">
<REFMETA>
-<REFENTRYTITLE>
+<REFENTRYTITLE id="sql-notify-ref">
NOTIFY
</REFENTRYTITLE>
<REFMISCINFO>SQL - Language Statements</REFMISCINFO>
<listitem>
<para>
Sets the maximum number of rows returned by a query to be unlimited.
-</varlistentry>
-
<para>
By default, there is no limit to the number of rows
returned by a query.
+</varlistentry>
+
</variablelist>
</VARLISTENTRY>
UNLISTEN
</REFNAME>
<REFPURPOSE>
-Stop listening for notification on a notify condition
+Stop listening for notification
</REFPURPOSE>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-10-07</DATE>
+<DATE>1998-10-19</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
UNLISTEN { <REPLACEABLE CLASS="PARAMETER">notifyname</REPLACEABLE> | * }
<REFSECT2 ID="R2-SQL-UNLISTEN-1">
<REFSECT2INFO>
-<DATE>1998-10-07</DATE>
+<DATE>1998-10-19</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TERM>
<LISTITEM>
<PARA>
-Name of notify condition to stop listening to.
+Name of previously registered notify condition.
<VARLISTENTRY>
<TERM>
<REFSECT2 ID="R2-SQL-UNLISTEN-2">
<REFSECT2INFO>
-<DATE>1998-10-07</DATE>
+<DATE>1998-10-19</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
<REFSECT1 ID="R1-SQL-UNLISTEN-1">
<REFSECT1INFO>
-<DATE>1998-10-07</DATE>
+<DATE>1998-10-19</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
+<command>UNLISTEN</command>
+is used to remove an existing <command>NOTIFY</command> registration.
UNLISTEN cancels any existing registration of the current
-<productname>Postgres</productname> backend as a listener on the notify
+<productname>Postgres</productname> session as a listener on the notify
condition <REPLACEABLE CLASS="PARAMETER">notifyname</REPLACEABLE>.
-The special condition name "*" means to cancel all listener registrations
-for the current backend.
+The special condition wildcard "*" cancels all listener registrations
+for the current session.
<para>
-The backend does not complain if you UNLISTEN something you were not
-listening for.
+<xref linkend="sql-notify-ref" endterm="sql-notify-ref">
+contains a more extensive
+discussion of the use of <command>LISTEN</command> and
+<command>NOTIFY</command>.
+<REFSECT2 ID="R2-SQL-UNLISTEN-3">
+<REFSECT2INFO>
+<DATE>1998-10-19</DATE>
+</REFSECT2INFO>
+<TITLE>
+Notes
+</TITLE>
<para>
+<REPLACEABLE CLASS="PARAMETER">classname</REPLACEABLE>
+needs not to be a valid class name but can be any string valid
+as a name up to 32 characters long.
+
+<para>
+The backend does not complain if you UNLISTEN something you were not
+listening for.
Each backend will automatically execute <command>UNLISTEN *</command> when
exiting.
<para>
-The reference page for <command>NOTIFY</command> contains a more extensive
-discussion of the use of <command>LISTEN</command> and
-<command>NOTIFY</command>.
+A restriction in some previous releases of
+ <productname>Postgres</productname> that a
+<REPLACEABLE CLASS="PARAMETER">classname</REPLACEABLE>
+which does not correspond to an actual table must be enclosed in double-quotes
+is no longer present.
+
+</REFSECT2>
<REFSECT1 ID="R1-SQL-UNLISTEN-2">
<TITLE>
Usage
</TITLE>
-<PARA>
-<ProgramListing>
-postgres=> listen virtual;
+
+<para>
+<programlisting>
+postgres=> LISTEN virtual;
LISTEN
-postgres=> notify virtual;
+postgres=> NOTIFY virtual;
NOTIFY
ASYNC NOTIFY of 'virtual' from backend pid '12317' received
-postgres=> unlisten virtual;
+</programlisting>
+
+<programlisting>
+postgres=> UNLISTEN virtual;
UNLISTEN
-postgres=> notify virtual;
+postgres=> NOTIFY virtual;
NOTIFY
-- notice no NOTIFY event is received
postgres=>
-</ProgramListing>
+</programlisting>
</REFSECT1>
<REFSECT2 ID="R2-SQL-UNLISTEN-4">
<REFSECT2INFO>
-<DATE>1998-10-07</DATE>
+<DATE>1998-10-19</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
There is no <command>UNLISTEN</command> in <acronym>SQL92</acronym>.
+
</REFENTRY>