Aging DB or FLUX thing? Cannot aggregate empty table bc string input type

Hi. I’m experiencing unexpected errors with data stored 3y ago, which are not happening with more recent data.

This is the query:

query_acu_1m = 'from(bucket:"'+bucket+'") |> range(start:2020-01-01T00:00:00Z, stop:2020-12-31T23:59:59Z) \
                        |> filter(fn: (r) => r["ID"] == C003) \
                        |> aggregateWindow(every: 1m, fn: sum, createEmpty: false) \
                        |> pivot(rowKey:["_time"], columnKey:["_field"], valueColumn: "_value") \
                        |> keep(columns: ["_time","ID","prec", "preccor"])'

With data before 2020-01-06, the error is

influxdb_client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'Vary': 'Accept-Encoding', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.2.0', 'X-Platform-Error-Code': 'invalid', 'Date': 'Wed, 29 Mar 2023 07:28:29 GMT', 'Transfer-Encoding': 'chunked'})
HTTP response body: b'{"code":"invalid","message":"unsupported input type for sum aggregate: string"}'

I have reduced the time range to 2020-01-05, which yields an empty table, and the aggregation still fails. With another day that has no data after that date, like 2020-02-06, the aggregation of empty data yields, unsurprisingly, an empty table.

Even more, following recommendations I was trying to add a column with all values casted to float:
|> map(fn:(r) => ({r with value_f: float(v:r._value) }))
With that string before the aggregateWindow line, the query works, as it does if the values are casted to strings (replace float with string).

Any ideas about what may be going on? Thanks!

The records in the DB look like this
result table ID _time preci preccor
0 _result 0 C003 2020-01-04 01:30:00+00:00 1.0 1.0
1 _result 0 C003 2020-01-04 01:37:00+00:00 1.0 1.0
2 _result 0 C003 2020-01-04 01:50:00+00:00 1.0 1.0
3 _result 0 C003 2020-01-04 01:56:00+00:00 1.0 1.0
4 _result 0 C003 2020-01-04 02:03:00+00:00 1.0 1.0
… … … … … … …
3427 _result 0 C003 2020-12-31 20:39:00+00:00 1.0 1.0

Hello @jdaniel006,
I think you’re really close you might wanna try the following though.

Does that help?

Thank you very much for your answer, @Anaisdg
I have’t tried yet, but it seems to be a way to avoid problems with the aggregation math.

However, my major concern a from the fact that the database behaves differently before and after a certain date. Any clues?