Skip to content

Instantly share code, notes, and snippets.

@yurikoval
Last active August 29, 2015 14:10
Show Gist options
  • Save yurikoval/ada3a3e45afd160e183c to your computer and use it in GitHub Desktop.
Save yurikoval/ada3a3e45afd160e183c to your computer and use it in GitHub Desktop.
Add sequence for PostgreSQL after migrating from MySQL
CREATE SEQUENCE feedbacks_id_seq;
ALTER TABLE feedbacks ALTER COLUMN id SET DEFAULT nextval('feedbacks_id_seq'::regclass);
ALTER SEQUENCE feedbacks_id_seq OWNED BY feedbacks.id;
select setval('feedbacks_id_seq', (select max(id)+1 from feedbacks), false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment