The problem is that the SQL expression:
<column> = ANY(<array>)
returns true if the scalar value in <column>
is equal to any value in <array>
comparing the values one by one. But your column is not a scalar value, it is an array and that's why PostgreSQL says:
operator does not exist: integer[] = integer
An operator to compare an array (left) to any integer (right) doesn't exists. To fix this you can use an intersection operator (&&
) (if you need to match just one id from both sets) or the equality operator (=
) if you want to match all array elements:
SELECT * FROM namespace_list WHERE namespace_ids && %s and application_id=%s
The trick here is that psycopg converts Python lists to literal arrays (ARRAY[...]
) that you can use anywhere you would use them in standard SQL.