Sequences
are not created automatically, like OIDs. Instead, you must
use the CREATE SEQUENCE command. Three functions control
the sequence counter, as shown in Table 
.
 
  | 
Figure 
 shows an example
of sequence creation and sequence function usage.
 
        test=> CREATE SEQUENCE functest_seq;
        CREATE
        test=> SELECT nextval('functest_seq');
         nextval 
        ---------
               1
        (1 row) 
         
        test=> SELECT nextval('functest_seq');
         nextval 
        ---------
               2
        (1 row) 
         
        test=> SELECT currval('functest_seq');
         currval 
        ---------
               2
        (1 row) 
         
        test=> SELECT setval('functest_seq', 100);
         setval 
        --------
            100
        (1 row) 
         
        test=> SELECT nextval('functest_seq');
         nextval 
        ---------
             101
        (1 row)
 
The first command creates the sequence, then various sequence functions are called. Note that the SELECTs do not include a FROM clause. Sequence function calls are not directly tied to any table. In the figure: