next up previous contents index
Next: Creating Sequences Up: Numbering Rows Previous: Object Identification Number Limitations

  
Sequences

POSTGRESQL offers another way of uniquely numbering rows--sequences. Sequences are named counters created by users. After its creation, a sequence can be assigned to a table as a column DEFAULT.  Using sequences, unique numbers can be automatically assigned during INSERT.

The advantage of sequences is that they avoid gaps in numeric assignment, as happens with OIDs.12.5 Sequences are ideal for use as user-visible identification numbers. If one customer is created today, and another is created tomorrow, then the two customers will have sequential numbers because no other table shares the sequence counter.12.6

Sequence numbers are generally unique only within a single table. For example, if a table has a unique row numbered 937, another table might have a row numbered 937 as well, assigned by a different sequence counter.


Bruce Momjian
2001-05-09