Skip to content

Commit 9380e5f

Browse files
committed
doc: improve create/alter sequence CYCLE syntax
Reported-by: Peter Smith Discussion: https://postgr.es/m/CAHut+PtqwZwPfGq62xq2614_ce2ejDmbB9CfP+a1azxpneFRBQ@mail.gmail.com Author: Peter Smith Backpatch-through: master
1 parent e28a271 commit 9380e5f

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

doc/src/sgml/ref/alter_sequence.sgml

+34-33
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
2727
[ AS <replaceable class="parameter">data_type</replaceable> ]
2828
[ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
2929
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE ]
30+
[ [ NO ] CYCLE ]
3031
[ START [ WITH ] <replaceable class="parameter">start</replaceable> ]
3132
[ RESTART [ [ WITH ] <replaceable class="parameter">restart</replaceable> ] ]
32-
[ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
33+
[ CACHE <replaceable class="parameter">cache</replaceable> ]
3334
[ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ]
3435
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET { LOGGED | UNLOGGED }
3536
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable class="parameter">new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
@@ -154,6 +155,38 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> S
154155
</listitem>
155156
</varlistentry>
156157

158+
<varlistentry>
159+
<term><literal>CYCLE</literal></term>
160+
<listitem>
161+
<para>
162+
The optional <literal>CYCLE</literal> key word can be used to enable
163+
the sequence to wrap around when the
164+
<replaceable class="parameter">maxvalue</replaceable> or
165+
<replaceable class="parameter">minvalue</replaceable> has been
166+
reached by
167+
an ascending or descending sequence respectively. If the limit is
168+
reached, the next number generated will be the
169+
<replaceable class="parameter">minvalue</replaceable> or
170+
<replaceable class="parameter">maxvalue</replaceable>,
171+
respectively.
172+
</para>
173+
</listitem>
174+
</varlistentry>
175+
176+
<varlistentry>
177+
<term><literal>NO CYCLE</literal></term>
178+
<listitem>
179+
<para>
180+
If the optional <literal>NO CYCLE</literal> key word is
181+
specified, any calls to <function>nextval</function> after the
182+
sequence has reached its maximum value will return an error.
183+
If neither <literal>CYCLE</literal> or <literal>NO
184+
CYCLE</literal> are specified, the old cycle behavior will be
185+
maintained.
186+
</para>
187+
</listitem>
188+
</varlistentry>
189+
157190
<varlistentry>
158191
<term><replaceable class="parameter">start</replaceable></term>
159192
<listitem>
@@ -207,38 +240,6 @@ ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> S
207240
</listitem>
208241
</varlistentry>
209242

210-
<varlistentry>
211-
<term><literal>CYCLE</literal></term>
212-
<listitem>
213-
<para>
214-
The optional <literal>CYCLE</literal> key word can be used to enable
215-
the sequence to wrap around when the
216-
<replaceable class="parameter">maxvalue</replaceable> or
217-
<replaceable class="parameter">minvalue</replaceable> has been
218-
reached by
219-
an ascending or descending sequence respectively. If the limit is
220-
reached, the next number generated will be the
221-
<replaceable class="parameter">minvalue</replaceable> or
222-
<replaceable class="parameter">maxvalue</replaceable>,
223-
respectively.
224-
</para>
225-
</listitem>
226-
</varlistentry>
227-
228-
<varlistentry>
229-
<term><literal>NO CYCLE</literal></term>
230-
<listitem>
231-
<para>
232-
If the optional <literal>NO CYCLE</literal> key word is
233-
specified, any calls to <function>nextval</function> after the
234-
sequence has reached its maximum value will return an error.
235-
If neither <literal>CYCLE</literal> or <literal>NO
236-
CYCLE</literal> are specified, the old cycle behavior will be
237-
maintained.
238-
</para>
239-
</listitem>
240-
</varlistentry>
241-
242243
<varlistentry>
243244
<term><literal>SET { LOGGED | UNLOGGED }</literal></term>
244245
<listitem>

doc/src/sgml/ref/create_sequence.sgml

+28-26
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ CREATE [ { TEMPORARY | TEMP } | UNLOGGED ] SEQUENCE [ IF NOT EXISTS ] <replaceab
2525
[ AS <replaceable class="parameter">data_type</replaceable> ]
2626
[ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
2727
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE ]
28-
[ START [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
28+
[ [ NO ] CYCLE ]
29+
[ START [ WITH ] <replaceable class="parameter">start</replaceable> ]
30+
[ CACHE <replaceable class="parameter">cache</replaceable> ]
2931
[ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ]
3032
</synopsis>
3133
</refsynopsisdiv>
@@ -193,6 +195,31 @@ SELECT * FROM <replaceable>name</replaceable>;
193195
</listitem>
194196
</varlistentry>
195197

198+
<varlistentry>
199+
<term><literal>CYCLE</literal></term>
200+
<term><literal>NO CYCLE</literal></term>
201+
<listitem>
202+
<para>
203+
The <literal>CYCLE</literal> option allows the sequence to wrap
204+
around when the <replaceable
205+
class="parameter">maxvalue</replaceable> or <replaceable
206+
class="parameter">minvalue</replaceable> has been reached by an
207+
ascending or descending sequence respectively. If the limit is
208+
reached, the next number generated will be the <replaceable
209+
class="parameter">minvalue</replaceable> or <replaceable
210+
class="parameter">maxvalue</replaceable>, respectively.
211+
</para>
212+
213+
<para>
214+
If <literal>NO CYCLE</literal> is specified, any calls to
215+
<function>nextval</function> after the sequence has reached its
216+
maximum value will return an error. If neither
217+
<literal>CYCLE</literal> or <literal>NO CYCLE</literal> are
218+
specified, <literal>NO CYCLE</literal> is the default.
219+
</para>
220+
</listitem>
221+
</varlistentry>
222+
196223
<varlistentry>
197224
<term><replaceable class="parameter">start</replaceable></term>
198225
<listitem>
@@ -221,31 +248,6 @@ SELECT * FROM <replaceable>name</replaceable>;
221248
</listitem>
222249
</varlistentry>
223250

224-
<varlistentry>
225-
<term><literal>CYCLE</literal></term>
226-
<term><literal>NO CYCLE</literal></term>
227-
<listitem>
228-
<para>
229-
The <literal>CYCLE</literal> option allows the sequence to wrap
230-
around when the <replaceable
231-
class="parameter">maxvalue</replaceable> or <replaceable
232-
class="parameter">minvalue</replaceable> has been reached by an
233-
ascending or descending sequence respectively. If the limit is
234-
reached, the next number generated will be the <replaceable
235-
class="parameter">minvalue</replaceable> or <replaceable
236-
class="parameter">maxvalue</replaceable>, respectively.
237-
</para>
238-
239-
<para>
240-
If <literal>NO CYCLE</literal> is specified, any calls to
241-
<function>nextval</function> after the sequence has reached its
242-
maximum value will return an error. If neither
243-
<literal>CYCLE</literal> or <literal>NO CYCLE</literal> are
244-
specified, <literal>NO CYCLE</literal> is the default.
245-
</para>
246-
</listitem>
247-
</varlistentry>
248-
249251
<varlistentry>
250252
<term><literal>OWNED BY</literal> <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable></term>
251253
<term><literal>OWNED BY NONE</literal></term>

0 commit comments

Comments
 (0)