【问题标题】:Create list of uuids in postgres?在postgres中创建uuid列表?
【发布时间】:2020-06-24 06:10:36
【问题描述】:

可以使用 postgres (https://www.postgresqltutorial.com/postgresql-uuid/) 生成 uuids 现在我需要更新缺少 uuids 的表。我无法弄清楚如何实现它。列 individual_uuid 具有唯一约束。有任何想法吗? ??? 应该替换为我需要的语法。

update foo_table set individual_uuid = ???? where individual_uuid is null

不工作:

update foo_table set individual_uuid = (SELECT uuid_generate_v1()) where individual_uuid is null

【问题讨论】:

    标签: postgresql uuid


    【解决方案1】:

    使用SELECT uuid_generate_v1() 会导致意想不到的结果,即每行都使用相同的值,因为子选择与主查询中的值不相关。

    改用uuid_generate_v1()

    UPDATE foo_table 
    SET    individual_uuid = uuid_generate_v1() 
    WHERE  individual_uuid IS NULL;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      • 2013-01-15
      • 2018-12-19
      • 2021-10-19
      • 1970-01-01
      相关资源
      最近更新 更多