Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for resetting autoincrement sequences #40

Open
timgraham opened this issue Jan 21, 2022 · 0 comments
Open

Add support for resetting autoincrement sequences #40

timgraham opened this issue Jan 21, 2022 · 0 comments

Comments

@timgraham
Copy link
Collaborator

When loading fixtures that have primary key values of autoincrement columns specified, Snowflake doesn't automatically update the sequence to the next available value. For example, after loading fixtures with pk=1 and pk=2 into a new table, the next object will be created with pk=1 (duplicating an existing value) instead of pk=3. PostgreSQL has the same issue and Django's DatabaseOperations.sequence_reset_sql() method is a hook to generate SQL that updates the next value of the sequence for each table:

SELECT setval(pg_get_serial_sequence(<table>, <column>), coalesce(max(<column>)), 1), max(column) IS NOT null)
FROM <table>

Since Snowflake's ALTER SEQUENCE doesn't provide a way to set the next value of the sequence, I'm not sure if this is feasible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant