apgdiff
apgdiff copied to clipboard
ALTER SEQUENCE ... RESTART where ... START is needed.
When comparing the following sequence from my live database:
devel_np=# \d classifications_id_seq Sequence "public.classifications_id_seq" Column | Type | Value ---------------+---------+------------------------ sequence_name | name | classifications_id_seq last_value | bigint | 302 start_value | bigint | 300 increment_by | bigint | 1 max_value | bigint | 9223372036854775807 min_value | bigint | 1 cache_value | bigint | 1 log_cnt | bigint | 31 is_cycled | boolean | f is_called | boolean | t Owned by: public.classifications.id
with this template:
CREATE SEQUENCE classifications_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; ALTER TABLE public.classifications_id_seq OWNER TO postgres; ALTER SEQUENCE classifications_id_seq OWNED BY classifications.id;
apgdiff recommended the following fix:
ALTER SEQUENCE classifications_id_seq RESTART WITH 1;
IMHO it should rather be "START WITH 1" as "RESTART" changes the current value which will of course result in duplicate key errors on further inserts.