I tried to use code from Check if sequence exists in Postgres (plpgsql).
To create sequence if it does not exists. Running this code two times causes an exception:>
Postgres doesn't have CREATE SEQUENCE IF NOT EXISTS
and if the table has default value using the sequence if you just drop the sequence, you might get error:
ERROR: cannot drop sequence (sequence_name) because other objects depend on it SQL state: 2BP01
For me, this one can help:
ALTER TABLE ALTER COLUMN id DROP DEFAULT;
DROP SEQUENCE IF EXISTS ;
CREATE sequence ;