Whenever possible, we try to handle this case (empty array) explicitly in the code and then we avoid the database call.
However, when we need a quick workaround we add a readable string condition that is always false:
'COLNAME array' = 'is empty'
where COLNAME is replaced with the real column-name
Details:
- the array cast
col = ANY (ARRAY[]::integer[]) from this answer requires us to know the column type
- the numeric check
0 = 1 from this answer works, but makes debugging tricky, because we don't know which column had the empty array
- workaround could be to add a comment after the condition: i.e.
0=1 --COLUMN array is empty
- but this can cause issues when multiple conditions are concatenated
i.e. you may get
0=1 --COLUMN array is empty AND OTHER_COL > 2
- workaround for this could be to append a line-break after the comment:
0=1 --COLUMN array is empty\n, but this is brittle and changes the desired format
- we cannot simply use
'COLNAME' = 'array is empty', because this may return true, when the column really contains the string array is empty