I\'d like to change the column type from an int
to a uuid
. I am using the following statement
ALTER TABLE tableA ALTER COLUMN colA
I'm bumping to this after a long time, but there is a way to convert your integer column to a UUID with some kind of backwards-compatibility, namely keeping a way to have a reference to your old values, rather than dropping your values. It comprises of converting your integer value to a hex string and then padding that with necesary zeroes to make up an artificial UUID.
So, assuming your current integer column is named ColA, the following statement would do it (mind the using
part):
ALTER TABLE tableA ALTER COLUMN ColA SET DATA TYPE UUID USING LPAD(TO_HEX(ColA), 32, '0')::UUID;