SQLTeam.com | Weblogs | Forums

Change primary key in PostgreSQL table

I have a very big database, each table have id column is big int (very long). Now my project is change and i have make it shorter, so to do it i need new func to create new id column as well as reset fk_key for all of them.

Can i create a loop to search all table use big-int id and in side of it i change a value and change fk as well.

Welcome

Why do you need to change from bigint?

My mean, in the past this project create by a not good id generate func, it make my id very long like: 21654615642132, so i need find new id generate func as well.

Thank for your help!

Changing from a bigint to an int will be problematic - because SQL Server has to modify every row in the table and validate each value meets the requirement of an integer.

If you have any FK's on those - they would have to be dropped, the FK column updated to the new data - and the FK recreated.

There is no simple fix where you can create a simple loop and make a mass change.

1 Like