mirror of
https://github.com/jbranchaud/til
synced 2026-01-11 02:58:01 +00:00
Add Restart A Sequence as a postgres til.
This commit is contained in:
14
postgres/restart-a-sequence.md
Normal file
14
postgres/restart-a-sequence.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Restart A Sequence
|
||||
|
||||
In postgres, if you are truncating a table or doing some other sort of
|
||||
destructive action on a table in a development or testing environment, you
|
||||
may notice that the id sequence for the primary key just keeps plugging
|
||||
along from where it last left off. The sequence can be reset to any value
|
||||
like so:
|
||||
|
||||
```sql
|
||||
> alter sequence my_table_id_seq restart with 1;
|
||||
ALTER SEQUENCE
|
||||
```
|
||||
|
||||
[source](http://www.postgresql.org/docs/current/static/sql-altersequence.html)
|
||||
Reference in New Issue
Block a user