The best way to reset a sequence to start back with number 1 is to execute the following:
ALTER SEQUENCE <tablename>_<id>_seq RESTART WITH 1
So, for example for the users
table it would be:
ALTER SEQUENCE users_id_seq RESTART WITH 1
More Related Contents:
- How to reset postgres’ primary key sequence when it falls out of sync?
- Why can I create a table with PRIMARY KEY on a nullable column?
- How to add an auto-incrementing primary key to an existing table, in PostgreSQL?
- Changing primary key int type to serial
- Composite PRIMARY KEY enforces NOT NULL constraints on involved columns
- PostgreSQL LIKE query performance variations
- Calculating and saving space in PostgreSQL
- PostgreSQL: ERROR: 42601: a column definition list is required for functions returning “record”
- I forgot the password I entered during postgres installation
- how to emulate “insert ignore” and “on duplicate key update” (sql merge) with postgresql?
- How do I efficiently select the previous non-null value?
- How do I do large non-blocking updates in PostgreSQL?
- How to configure PostgreSQL to accept all incoming connections
- Postgresql : Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections [duplicate]
- Dynamic SQL (EXECUTE) as condition for IF statement
- uWSGI, Flask, sqlalchemy, and postgres: SSL error: decryption failed or bad record mac
- serial in postgres is being increased even though I added on conflict do nothing
- Can’t connect to Postgresql on port 5432
- Spark Dataframes UPSERT to Postgres Table
- PostgreSQL Error: Relation already exists
- How to make a select with array contains value clause in psql
- Optimize Postgres query on timestamp range
- Use variable set by psql meta-command inside of DO block
- Sorting array elements
- How do I handle opening/closing Db connection in a Go app?
- Error: Column does not exist in postgresql for update [duplicate]
- How can I ensure that a materialized view is always up to date?
- PostgreSQL jsonb, `?` and JDBC
- Syntax error at end of input in PostgreSQL
- Error when pushing data to Heroku: time zone displacement out of range