1

So im working on a database at the moment, and i can see there are loads of sequences. I was wondering how sequences link up to their corresponding column in order to increment the value.

for example if i create a new table with a column names ID how would i apply a sequence to that column.

1 Answers1

1

Typically, sequences are created implicitly. With a serial column or (alternatively) with an IDENTITY column in Postgres 10 or later. Details:

Sequences are separate objects internally and can be "owned" by a column, which happens automatically for the above examples. (But you can also have free-standing sequences.) They are incremented with the dedicated function nextval() that is used for the column default of above columns automatically. More sequence manipulation functions in the manual.

Details:

Or you can use ALTER SEQUENCE to manipulate various properties.

Privileges on sequences have to be changed explicitly for serial columns, while that happens implicitly for the newer IDENTITY columns.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228