【问题标题】:PostgreSQL: Check if any item from array exists in the db property, which is array tooPostgreSQL:检查数组中的任何项目是否存在于 db 属性中,该属性也是数组
【发布时间】:2018-06-28 11:36:10
【问题描述】:

寻找一种方法来检查给定数组的一项是否存在于 db 属性中,该属性也是一个数组。 我有一个表'Events',它有一个属性weekDays,它是一个数字数组[1,2,3,4,5]时间>。 给定一个数组 searchDays,它是 [2,3],我想检查其中一项是否存在于 weekDays 中。

【问题讨论】:

    标签: sql arrays postgresql


    【解决方案1】:

    这意味着您需要寻找重叠。运营商是&&

    SELECT * FROM Events where weekDays && ARRAY[2,3]
    

    【讨论】:

      【解决方案2】:

      you are looking for intersecion I suppose:

      t=# with c(weekdays,searchdays) as (values(array[1,2,3,4,5],array[2,3]))
      select weekdays && searchdays from c;
       ?column?
      ----------
       t
      (1 row)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-30
        • 2016-09-24
        • 2014-05-16
        • 1970-01-01
        • 2019-02-16
        • 1970-01-01
        • 1970-01-01
        • 2019-06-11
        相关资源
        最近更新 更多