Postgresql 9.4, Make existing primary key as SERIAL

最后都变了- 提交于 2021-01-28 00:13:50

问题


I am using postgresql 9.4. I want to change existing primary key with serial. My query is not working. Anybody know how to do this?

Alter table 'table_name' alter column id BIGSERIAL;

There should be a single query to modify a particular column. I didn't see that


回答1:


CREATE SEQUENCE table_name_id_seq
   OWNED BY table_name.id;

ALTER TABLE table_name
   ALTER id
      SET DEFAULT nextval('table_name_id_seq'::regclass);


来源:https://stackoverflow.com/questions/41847396/postgresql-9-4-make-existing-primary-key-as-serial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!