PostgreSQL - Reset Identity on pgAdmin


執行目標:在pgAdmin上重新設定id值


前言

使用pgAdmin建立table以及欄位時,可直接將identity寫入,並設定最大最小值,如附圖所示,一旦資料更動(新增or刪除),想要重新設定id值,可透過以下兩個步驟來完成。


pgAdmin中id欄位設定畫面


正式操作

First :
1.Get the table sequence you want to reset, remember full table name(contain schema) usually it will like schema.tablename_id_seq
2.You can check the relation via the following sql command:
SELECT pc.relname FROM pg_class pc WHERE pc.relkind = 'S'

Second:
Alter SEQUENCE schema.tablename_id_seq RESTART WITH 1
UPDATE schema.tablename SET id = nextval('schema.tablename_id_seq');





((我之前到底為啥用英文寫...太有才了吧XD

Flow Finish


留言

這個網誌中的熱門文章

Export query as csv from beeline Hive(on Linux)

PostgreSQL - COPY command not work on server(pgAdmin)