Postgres allows for auto-increment of the Primary Key value SERIAL
is used at DDL. With this, a sequence
property for the table is also created along with the table. However, when tuples are inserted manually, the sequence
current value
does not get updated.
For One table at a time we can use SQL like this
SELECT setval('<table>_id_seq', COALESCE((SELECT MAX(id) FROM your_table), 1), false);
wherein we need to manually set the <table>_id_seq' and
id' attribute name.
The problem becomes labourious if there are multiple tables. So is there any generalised method to set current value
for all sequences
to the MAX(<whatever_sequence_attribute_is>)
?