N
Neon2y ago
hilarious-sapphire

Column from Integer to UUID

I was trying to change the integer type to UUid but it didn't change. What steps to follow
4 Replies
ambitious-aqua
ambitious-aqua2y ago
They are very different data types. Is it a change of primary key? I assume the best approach would be to: 1. Create a new column for the UUID (using ALTER table with ADD COLUMN) 2. Insert UUIDs in the new column (using UPDATE thetable SET uuid = generate_uuid() or similar) 3. Update foreign key relationships 4. Drop the integer column (ALTER table with DROP COLUMN)
genetic-orange
genetic-orange2y ago
Presuming this is being done in a production environment, be aware that step 2 is dangerous, and you may want to do it in batches rather than 1 single sql statement.
ambitious-aqua
ambitious-aqua2y ago
You can use a Neon branch to test it out too 🎉
wise-white
wise-white2y ago
Thanks a lot for the guidance. I'll keep the above in mind with the approaches that I'll be following.

Did you find this page helpful?