I am trying to run the multi-column in parameter, which also matches null values. Right now I'm using coalesce like this:
select * from table
where (coalesce(foo, ''), coalesce(bar, '')) in (('foo_val', 'bar_val'), ('foo_val', ''));
However, for integer columns, this is an invalid input syntax for an integer: "" on coalescing. I could combine at -1 instead of an empty string, but wondered if there was a more elegant solution.
I / O example:
Table data:
{{foo: 1, bar: 2}, {foo: 1, bar: NULL}}
User input: [(1, 2), (1, zero)]
Expected result: both lines .
EDIT: I will try to clarify what I am trying to do: I want to map database rows with several combinations of column values set by the user. That is, if the user enters [(1,2), (3,4)], I would like to return the rows where column_A == 1 AND column_B == 2, OR column_A == 3 AND column_B == 4. There, where I ran into difficulties, the user can enter NULL and match it like any other value. Therefore, if the user enters [(1, NULL)], I would like to return the rows where column_A == 1 AND column_B == NULL (but note that I would not want to return them for the previous query, since the user didn ' t indicate that it needs rows with NULL values in column_B).
source
share