postgres - comparing two arrays

后端 未结 2 475
情书的邮戳
情书的邮戳 2021-01-01 12:58

postgres has an array data type, in this case a numeric array:

CREATE TABLE sal_emp (name text, pay_by_quarter integer[]);
INSERT INTO sal_emp VALUES (\'one\         


        
相关标签:
2条回答
  • 2021-01-01 13:37

    figured it ... there's an && operator

    http://www.postgresql.org/docs/8.2/static/functions-array.html

    "&& overlap (have elements in common) ARRAY[1,4,3] && ARRAY[2,1]"

    0 讨论(0)
  • 2021-01-01 14:03

    Trying not to plagiarise pstanton's answer, but clarifying a use case.

    To have a condition that is satisfied by any of two (or more) columns having any of a list of values:

     select * from mytable
     where array(col1, col2) && array('foo', 'bar', baz')
    
    0 讨论(0)
提交回复
热议问题