This script is intended to automatically fix the sequence numbers for all tables in the current database.
This is accomplished through the use of the setval()
command, which we provide with the next ID value we wish to make use of.
We use the setval(sequence, number, is_called)
overload
and set is_called = false
in conjunction with COALESCE(MAX + 1, 1)
to ensure that, with an empty table, the next sequence
value is 1
as expected.