Skip to content

Commit 3eabc44

Browse files
committed
Tweak CREATE SEQUENCE grammar to be more SQL1999 standards compliant.
Neil Conway
1 parent ebb5318 commit 3eabc44

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

doc/src/sgml/ref/create_sequence.sgml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.28 2002/05/18 15:44:47 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.29 2002/11/10 00:10:20 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -21,9 +21,9 @@ PostgreSQL documentation
2121
<date>1999-07-20</date>
2222
</refsynopsisdivinfo>
2323
<synopsis>
24-
CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT <replaceable class="parameter">increment</replaceable> ]
24+
CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
2525
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> ]
26-
[ START <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ CYCLE ]
26+
[ START [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
2727
</synopsis>
2828

2929
<refsect2 id="R2-SQL-CREATESEQUENCE-1">
@@ -130,8 +130,8 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</rep
130130
<term>CYCLE</term>
131131
<listitem>
132132
<para>
133-
The optional CYCLE keyword may be used to enable the sequence
134-
to wrap around when the
133+
The optional <option>CYCLE</option> keyword may be used to enable
134+
the sequence to wrap around when the
135135
<replaceable class="parameter">maxvalue</replaceable> or
136136
<replaceable class="parameter">minvalue</replaceable> has been
137137
reached by
@@ -140,11 +140,22 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</rep
140140
<replaceable class="parameter">minvalue</replaceable> or
141141
<replaceable class="parameter">maxvalue</replaceable>,
142142
respectively.
143-
Without CYCLE, after the limit is reached <function>nextval</> calls
144-
will return an error.
145143
</para>
146144
</listitem>
147145
</varlistentry>
146+
147+
<varlistentry>
148+
<term>NO CYCLE</term>
149+
<listitem>
150+
<para>
151+
If the optional <option>NO CYCLE</option> keyword is specified, any
152+
calls to <function>nextval</function> after the sequence has reached
153+
its maximum value will return an error. If neither
154+
<option>CYCLE</option> or <option>NO CYCLE</option> are specified,
155+
<option>NO CYCLE</option> is the default.
156+
</para>
157+
</listitem>
158+
</varlistentry>
148159
</variablelist>
149160
</para>
150161
</refsect2>

src/backend/commands/sequence.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.88 2002/09/22 19:42:50 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.89 2002/11/10 00:10:20 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -798,11 +798,7 @@ init_params(CreateSeqStmt *seq, Form_pg_sequence new)
798798
else if (strcmp(defel->defname, "cache") == 0)
799799
cache_value = defel;
800800
else if (strcmp(defel->defname, "cycle") == 0)
801-
{
802-
if (defel->arg != (Node *) NULL)
803-
elog(ERROR, "DefineSequence: CYCLE ??");
804-
new->is_cycled = true;
805-
}
801+
new->is_cycled = (defel->arg != NULL);
806802
else
807803
elog(ERROR, "DefineSequence: option \"%s\" not recognized",
808804
defel->defname);

src/backend/parser/gram.y

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.374 2002/11/09 23:56:39 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.375 2002/11/10 00:10:20 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -1893,11 +1893,15 @@ OptSeqElem: CACHE NumericOnly
18931893
}
18941894
| CYCLE
18951895
{
1896-
$$ = makeDefElem("cycle", (Node *)NULL);
1896+
$$ = makeDefElem("cycle", (Node *)true);
18971897
}
1898-
| INCREMENT NumericOnly
1898+
| NO CYCLE
18991899
{
1900-
$$ = makeDefElem("increment", (Node *)$2);
1900+
$$ = makeDefElem("cycle", (Node *)false);
1901+
}
1902+
| INCREMENT opt_by NumericOnly
1903+
{
1904+
$$ = makeDefElem("increment", (Node *)$3);
19011905
}
19021906
| MAXVALUE NumericOnly
19031907
{
@@ -1907,12 +1911,16 @@ OptSeqElem: CACHE NumericOnly
19071911
{
19081912
$$ = makeDefElem("minvalue", (Node *)$2);
19091913
}
1910-
| START NumericOnly
1914+
| START opt_with NumericOnly
19111915
{
1912-
$$ = makeDefElem("start", (Node *)$2);
1916+
$$ = makeDefElem("start", (Node *)$3);
19131917
}
19141918
;
19151919

1920+
opt_by: BY {}
1921+
| /* empty */ {}
1922+
;
1923+
19161924
NumericOnly:
19171925
FloatOnly { $$ = $1; }
19181926
| IntegerOnly { $$ = $1; }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy