Search code examples
sqlunit-testingpostgresqlhsqldb

Alter auto-generated sequence


I use this to create auto-incremented id columns:

  id  BIGSERIAL                                -- psql
  id  BIGINT GENERATED BY DEFAULT AS IDENTITY  -- hsql

Now in unit tests i'd like to reset those sequences between tests.

Is this possible? I target PostgreSQL and HSQLDB


Solution

  • TRUNCATE table RESTART IDENTITY;
    

    http://www.postgresql.org/docs/9.2/static/sql-truncate.html
    http://hsqldb.org/doc/guide/dataaccess-chapt.html#dac_truncate_statement