Postgresql change column type from int to UUID

后端 未结 7 1597
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 13:26

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          


        
7条回答
  •  太阳男子
    2020-12-23 14:06

    WARNING: I've noticed some comments and answers that try to cast integers to a UUID4.

    You must not cast or force-set uuid values. They must be generated using functions relating to RFC4122.

    UUIDs must be randomly distributed or they will not work. You cannot cast or enter your own UUIDs as they will not be properly distributed. This can lead to bad actors guessing your sequencing or finding other artifacts or patterns in your UUIDs that will lead them to discover others.

    Any answer that converts to char types and then to uuid may lead to these kinds problems.

    Follow any answer here that refers to 'uuid_generate_v4'. Ignore ones that are casting or setting without using the formal functions.

提交回复
热议问题