This:
table3.status_id in (statuses)
can be simplified for the example into:
regress=> SELECT 1 IN (ARRAY[1,2,3]);
ERROR: operator does not exist: integer = integer[]
LINE 1: SELECT 1 IN (ARRAY[1,2,3]);
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
... but IN
expects a literal list, eg:
regress=> SELECT 1 IN (1, 2, 3);
Since you want to pass an array, you'll want to use = ANY(...)
which expects an array input:
regress=> SELECT 1 = ANY (ARRAY[1,2,3]);
?column?
----------
t
(1 row)