Search code examples
postgresqlsequencepostgresql-9.3alter

Avoid use of a single number in a PostgreSQL 9 sequence


Would it be possible with a sequence in Postgre to skip an Id? For example the sequence last id is 5, I want to set 7 as being used, so that the next Ids generated will be 6 then 8?


Solution

  • For a one time skip,

    SELECT nextval('sequence_name');
    

    This will burn an id and increment the sequence.

    For doing evens only,

    CREATE SEQUENCE sequence_name INCREMENT BY 2;