Performing conditional arithmetic in InfluxQL

I have got a field in InfluxDB that I want to correct for integer overflow. Given the field FieldA, I want a select statement that returns: FieldA - 65536 if FieldA > 32768, else FieldA.

I can do this using multiple select statements, but I want to use the output in a Grafana panel, and that does not seem to work with multiple statements. Is there a way to perform conditional arithmetic in a single statement? Or any other suggestions?

Hello @EthanG,
Welcome!! What version of Influx are you using? If you’re using 1.8+ you can take advantage of Flux. I think you might have more success using Flux. That query in Flux would look something like this:

from(bucket: "mybucket")
  |> range(start: -1d)
  |> filter(fn: (r) => r["_measurement"] == "m0")
  |> filter(fn: (r) => r["_field"] == "f0")
  |> map(fn: (r) => ({ r with _value: if r._value >= 32768  then (r._value - 65536)
                                     else r._value}))