Search code examples
sqlpostgresqlsql++

Postgres equivalent of ANY ... SATISFIES in n1ql to combine ANY and IN


I know in n1ql, you can write a query condition that combines ANY and IN operators like so:

WHERE ANY v IN [v1, v2] SATISFIES v IN c1 END

I'm trying to rewrite the same query in postgres, and right now I'm using OR like so:

WHERE v1 IN c1
OR v2 IN c1

But is there an equivalent to SATISFIES that I can use instead?


Solution

  • Assuming that c1 is a subquery, you could use the array overlap operator &&:

    WHERE ARRAY[v1, v2] && array(SELECT ...)
    

    That will be TRUE if the arrays have elements in common, which should do what you want.