将 msb 和 lsb postgres 列迁移到 uuid 列

Migrate msb & lsb postgres columns into uuid column

我有 2 个 bigint 列,msblsb,我想将它们合并成一个 uuid 列。

是否可以更改 table 以添加 uuid 列并从 msblsb 值生成 uuid 值? msb 应该是 uuid 的前 64 位,而 lsb 应该是后 64 位。

添加一个新的 uuid 类型的列(假设 sb;首先可以为空)。然后用

更新你的 table
UPDATE table_name
SET    sb = (lpad(to_hex(msb), 16, '0') || lpad(to_hex(lsb), 16, '0'))::uuid

然后您可以将其设为主键(并可选择删除 msblsb)。