Sequences are not automatically created like OIDs. You must use the
CREATE SEQUENCE command to create them. Sequences are usually given
names to match the table name. There are three functions that control access
to sequence numbers. They are listed in table .
Sequence number access functions
Returns the next available sequence number, and updates the counter
Returns the sequence number from the previous nextval() call
Sets the sequence number counter to the specified value
Figure shows examples of sequence function
Examples of sequence function use
First, the sequence is created. Next, various sequence functions are called.
Note the SELECTs do not have a FROM clause. The function calls
are not directly tied to the customer table and do not access the customer
table. Notice the nextval() function returns ever increasing values.
Currval() shows the previous sequence value without incrementing it.
Setval() sets the sequence counter to a new value.