I have a serial
id in my application table. However, I would like to insert a single 0
id record to mean global.
Is there a way I can insert this into my table without affecting the counter?
insertpostgresqlsequence
I have a serial
id in my application table. However, I would like to insert a single 0
id record to mean global.
Is there a way I can insert this into my table without affecting the counter?
Best Answer
Sure, just do it. The counter only gets incremented when you call a Sequence Manipulation Function. In the case when you don't explicitly specify a value, the
DEFAULT
triggers a call tonextval(sequence_name)
PostgreSQL 10+
It should be noted, that
serial
is the old and antiquated method of doing this. You should be using the standardizedIDENTITY COLUMNS
See also
CREATE TABLE
(syntax forIDENTITY COLUMNS
)CREATE SEQUENCE
(which has the options for the columns)