Alter/change default value for sequence on postgreSQL
Solution 1:
First, pg_get_serial_sequence
will return the sequence name only if you have added a dependency between the sequence and the column; it does not look at theDEFAULT
clause You can add a dependency with
ALTER SEQUENCE test_thing_thing_id_seq
OWNED BY test_thing(id);
You can change the sequence value with
SELECT setval('test_thing_thing_id_seq', 42);
That can probably also be done with a GUI client like HeidiSQL, but I don't know because I don't use GUI clients
Changing the sequence value can cause problems if the new value is lower than the maximum of id
in the table: future INSERT
s could result in primary key constraint violation errors