【问题标题】:Constrain a numeric array to be sorted and unique [duplicate]约束要排序且唯一的数字数组
【发布时间】:2017-01-02 11:04:57
【问题描述】:

我在 Postgres 数据库中有一个 numeric[] 列,它应该代表一个时间数组(如 {0.5 seconds, 2 seconds, 3.25 seconds, ...})。因此,我想将数组中的值限制为唯一且已排序。有什么办法吗?

我看到了一些答案,这些答案提出了intarray 模块的sortuniq 函数。 numeric/decimal有类似的吗?

【问题讨论】:

    标签: sql arrays postgresql database-design check-constraints


    【解决方案1】:

    附加模块intarray 仅用于整数。你不能将它用于数据类型numeric,我也不知道numeric 有任何类似的东西。

    如果您的数字不超过 n 个小数位并且可以缩放为整数,则可以乘以 10^n 并改用integer 操作。缩小输出...

    除此之外,我之前回答过同样的问题(排序对于 sets 来说是微不足道的):

    【讨论】:

      猜你喜欢
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 2011-04-07
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多