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?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
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 to
CREATE TABLE foo ( id serial ); INSERT INTO foo (id) VALUES (0);
It should be noted, that
serial is the old and antiquated method of doing this. You should be using the standardized
CREATE TABLE foo ( id int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY ); INSERT INTO foo (id) VALUES (0);