doc: improve create/alter sequence CYCLE syntax
authorBruce Momjian
Tue, 20 Aug 2024 00:18:03 +0000 (20:18 -0400)
committerBruce Momjian
Tue, 20 Aug 2024 00:18:03 +0000 (20:18 -0400)
Reported-by: Peter Smith
Discussion: https://postgr.es/m/CAHut+PtqwZwPfGq62xq2614_ce2ejDmbB9CfP+a1azxpneFRBQ@mail.gmail.com

Author: Peter Smith

Backpatch-through: master

doc/src/sgml/ref/alter_sequence.sgml
doc/src/sgml/ref/create_sequence.sgml

index 7be36cf466d2c736fba2f0b420b25b728a62fef4..a998ccc7ead2f27c7891134ae17e752b6bce4f6e 100644 (file)
@@ -27,9 +27,10 @@ ALTER SEQUENCE [ IF EXISTS ] name
     [ AS data_type ]
     [ INCREMENT [ BY ] increment ]
     [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
+    [ [ NO ] CYCLE ]
     [ START [ WITH ] start ]
     [ RESTART [ [ WITH ] restart ] ]
-    [ CACHE cache ] [ [ NO ] CYCLE ]
+    [ CACHE cache ]
     [ OWNED BY { table_name.column_name | NONE } ]
 ALTER SEQUENCE [ IF EXISTS ] name SET { LOGGED | UNLOGGED }
 ALTER SEQUENCE [ IF EXISTS ] name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
@@ -154,6 +155,38 @@ ALTER SEQUENCE [ IF EXISTS ] name S
       
      
 
+     
+      CYCLE
+      
+       
+        The optional CYCLE key word can be used to enable
+        the sequence to wrap around when the
+        maxvalue or
+        minvalue has been
+        reached by
+        an ascending or descending sequence respectively. If the limit is
+        reached, the next number generated will be the
+        minvalue or
+        maxvalue,
+        respectively.
+       
+      
+     
+
+     
+      NO CYCLE
+      
+       
+        If the optional NO CYCLE key word is
+        specified, any calls to nextval after the
+        sequence has reached its maximum value will return an error.
+        If neither CYCLE or NO
+        CYCLE are specified, the old cycle behavior will be
+        maintained.
+       
+      
+     
+
      
       start
       
@@ -207,38 +240,6 @@ ALTER SEQUENCE [ IF EXISTS ] name S
       
      
 
-     
-      CYCLE
-      
-       
-        The optional CYCLE key word can be used to enable
-        the sequence to wrap around when the
-        maxvalue or
-        minvalue has been
-        reached by
-        an ascending or descending sequence respectively. If the limit is
-        reached, the next number generated will be the
-        minvalue or
-        maxvalue,
-        respectively.
-       
-      
-     
-
-     
-      NO CYCLE
-      
-       
-        If the optional NO CYCLE key word is
-        specified, any calls to nextval after the
-        sequence has reached its maximum value will return an error.
-        If neither CYCLE or NO
-        CYCLE are specified, the old cycle behavior will be
-        maintained.
-       
-      
-     
-
      
       SET { LOGGED | UNLOGGED }
       
index 34e9084b5ccbf888923e7813b9d98fdbd248a824..1e283f13d15c64eb6e6f76a372d0007b5ba0aa32 100644 (file)
@@ -25,7 +25,9 @@ CREATE [ { TEMPORARY | TEMP } | UNLOGGED ] SEQUENCE [ IF NOT EXISTS ] 
     [ AS data_type ]
     [ INCREMENT [ BY ] increment ]
     [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
-    [ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
+    [ [ NO ] CYCLE ]
+    [ START [ WITH ] start ]
+    [ CACHE cache ]
     [ OWNED BY { table_name.column_name | NONE } ]
 
  
@@ -193,6 +195,31 @@ SELECT * FROM name;
     
    
 
+   
+    CYCLE
+    NO CYCLE
+    
+     
+      The CYCLE option allows the sequence to wrap
+      around when the 
+      class="parameter">maxvalue or 
+      class="parameter">minvalue has been reached by an
+      ascending or descending sequence respectively. If the limit is
+      reached, the next number generated will be the 
+      class="parameter">minvalue or 
+      class="parameter">maxvalue, respectively.
+     
+
+     
+      If NO CYCLE is specified, any calls to
+      nextval after the sequence has reached its
+      maximum value will return an error.  If neither
+      CYCLE or NO CYCLE are
+      specified, NO CYCLE is the default.
+     
+    
+   
+
    
     start
     
@@ -221,31 +248,6 @@ SELECT * FROM name;
     
    
 
-   
-    CYCLE
-    NO CYCLE
-    
-     
-      The CYCLE option allows the sequence to wrap
-      around when the 
-      class="parameter">maxvalue or 
-      class="parameter">minvalue has been reached by an
-      ascending or descending sequence respectively. If the limit is
-      reached, the next number generated will be the 
-      class="parameter">minvalue or 
-      class="parameter">maxvalue, respectively.
-     
-
-     
-      If NO CYCLE is specified, any calls to
-      nextval after the sequence has reached its
-      maximum value will return an error.  If neither
-      CYCLE or NO CYCLE are
-      specified, NO CYCLE is the default.
-     
-    
-   
-
    
     OWNED BY table_name.column_name
     OWNED BY NONE