diff --git a/README.md b/README.md index be6d195..47cb6f8 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [List All Columns Of A Specific Type](postgres/list-all-columns-of-a-specific-type.md) - [List All Versions Of A Function](postgres/list-all-versions-of-a-function.md) - [List Database Users](postgres/list-database-users.md) +- [Restart A Sequence](postgres/restart-a-sequence.md) - [Send A Command To psql](postgres/send-a-command-to-psql.md) - [Special Math Operators](postgres/special-math-operators.md) - [String Contains Another String](postgres/string-contains-another-string.md) diff --git a/postgres/restart-a-sequence.md b/postgres/restart-a-sequence.md new file mode 100644 index 0000000..27482e5 --- /dev/null +++ b/postgres/restart-a-sequence.md @@ -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)