Cannot use "overlap" query predicate when one array is empty. Is there a workaround or a solution?

Answered

Hi! I have a very annoying problem to which I cannot find a proper solution.

In an Database Query -> Query all data, I want to be able to compare two arrays in the where clause with the overlap predicate.

Example : Where input:text[] my_input_value_array overlaps table.value_array.

However, I have two major annoyances :

  1. It does NOT work with variables, only with input declared as Text[].
    The array comparison outside of DB context only works with API or function inputs. It will return the following otherwise : stripos(): Argument #1 ($haystack) must be of type string, array given

  2. Does not work when one of the array is empty. It will return 1st /2nd operand must be json or a scalar array.(even if [] is technically an empty scalar array)

Of course, I could "join" the database array into the query and use the "in" query filter, but it's a bit overkill and I'm not sure if it's an optimal way to do so performance wise. I'm a bit in an unfortunate situation here when having an empty array in one of the two operands and it can happen both in the input or the database.

Is there something I am missing or doing wrong? Would there be a solution or a workaround to this problem?

Thank you!

2 replies