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
deep-jade•2y 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
)correct-apricot•2y 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.
deep-jade•2y ago
You can use a Neon branch to test it out too 🎉
conscious-sapphire•2y ago
Thanks a lot for the guidance. I'll keep the above in mind with the approaches that I'll be following.