postgresqlHow can I use the PostgreSQL nextval function?
The PostgreSQL nextval
function can be used to generate a sequence of unique values. It is typically used to create a unique identifier for a row in a table.
Example
CREATE SEQUENCE my_sequence START 1;
SELECT nextval('my_sequence');
Output example
1
The code above creates a sequence called my_sequence
starting at 1 and then generates the next value in the sequence.
The code can be modified to set different start values, increments, min/max values, and caching.
Parts of the code:
CREATE SEQUENCE
- Creates a sequence with a given nameSTART
- Sets the starting value for the sequenceSELECT nextval
- Generates the next value in the sequence
Helpful links
More of Postgresql
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL and ZFS together?
- How do I set the PostgreSQL work_mem parameter?
- How can I use PostgreSQL with YAML?
See more codes...