It looks like the alert always sees a query result as a string and not a number. So an alert configured to trigger when field = 0 never triggers because "0" does not equal 0.
The alerts seems to evaluate fine for targets that are obviously strings. If the alert should trigger if field = boyhowdy then the alert triggers when field is "boyhowdy".
SELECT 0 "value"value = 0The converse is also true, by the way.
value != 0I believe this is happens cause the threshold input field has been changed to accept texts (to accommodate text comparisons) so all new alerts yield a string from the threshold value.
@rauchy @kravets-levko wdyt of handling this in the backend - casting both args to string for ==/!= and to int for the rest?
https://github.com/getredash/redash/blob/5d585036239e40973adebceadc0dfcceb82e2250/redash/models/__init__.py#L826-L847
I think the solution could be something like: if alert's threshold value contains numeric string and query result's column type is number - cast both to number; otherwise cast both to string:
| Query result column type | Alert threshold value | Cast both to |
|--|--|--|
| number | string containing number | number |
| number | non-numeric string | string |
| other types | string containing number | string |
| other types | non-numeric string | string |
I think that if query result is a number, then we should try to cast both to number. In other cases: use a string.
Because the operation options we show are based on the query result type, the threshold should adhere. We might want to enforce this in the UI.
Not sure I understand why casting-by-value would be preferable to casting-by-operation.
Not sure I understand why casting-by-value would be preferable to casting-by-operation.
Because strings and numbers have different behavior, for example:
In case of a number 0.0 == 0, but in case of strings '0.0' != '0'.
Aha. So I propose the following:
|Operator| Cast |
|--|--|
|== / !=|Threshold to result value type |
| Other | Both to number |
Not sure about this, but perhaps we can hint at string values with apostrophes.

@susodapop reopening as the fix wasn't pushed to this repo yet.
Most helpful comment
Not sure about this, but perhaps we can hint at string values with apostrophes.