'select condition with provided array clauses
I am trying to construct such a query where I have multiple postgres arrays with the same size and I would like to use it in sql where clause.
I have condition1 and condition2 arrays I am trying to select all rows where one row meets condition1[0] and condition2[0] another one meets condition1[1] and condition2[1]
In another word it could be rewritten as
select * from table1 where
(col1=condition1[0] and col2=condition2[0])
OR (col1=condition1[1] and col2=condition2[1])
OR (col1=condition1[2] and col2=condition2[2])
Array can be arbitrary size in the order of few thousands. What is the right way of constructing such query.
Solution 1:[1]
SELECT
*
FROM
Your_table_name
WHERE
Array(col1)= ANY (col2) OR Array(col2) = ANY(col1);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aman |
