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

Time:10-14

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?

CodePudding user response:

I was also thinking along the lines of an array, something like this...

    select *
    from my_table
    where array[v1, v2] @> array[c1]  

db-fiddle: https://www.db-fiddle.com/f/9qfJzyF6sfoNfFxRKtXa1W/0

CodePudding user response:

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.

  • Related