How can I set the starting point for the primary key (ID) column in Postgres via a rails migration How can I set the starting point for the primary key (ID) column in Postgres via a rails migration sql sql

How can I set the starting point for the primary key (ID) column in Postgres via a rails migration


Have no idea about rubies and railroads part, but query you're talking about is

ALTER SEQUENCE reports_something_seq RESTART 1000;

You will have to look up your table for the sequence name and postgresql documentation for general education regarding the matter ;-)


In postgres, like in many other databases, auto increment feature is done via Sequences. For every Serial and the likes fields sequences are created automatically by Postres for you and named something like TABLENAME _ COLUMNNAME _ seq.

So, you have to just alter the corresponding sequence, like this:

ALTER SEQUENCE example_id_seq RESTART 1000 -- corrected from START