How to use the function tofloat() convert string to float in flux?

I have using the sql [ SELECT toFloat(“1”) FROM “devdata” ] to select the data,but it is error. I also using the sql [select “1”::float from “devdata”]to select,but it cannot convert the string to the float .Could you please help me ,thanks a lot.

Hello @zhangjing,
To convert the “_value” column to a float use the toFloat() function.
To convert other columns to a float us the float() function:

from(bucket: "my_bucket")
  |> range(start: -1m)
  |> filter(fn:(r) => r._measurement == "my_measurement" )
  |> map(fn:(r) => ({ r with my_column: float(v: r.my_column) }))

Hello @Anaisdg thanks a lot. I tried the SQL [SELECT float(“1”) FROM “devdata”] to select the data ,but it is error. I am sorry for this ,i can’t understand the example. I don’t know how to use it in SQL statements. If you know this ,Could you please give me a sql example,thanks a lot .

Hello @zhangjing,
My apologies I saw you were using the toFloat function. That’s only something you can do with Flux. Not with InfluxQL (InfluxDB doesn’t support SQL).

Hello @Anaisdg Thanks a lot .I’m going to learn flux to solve this problem.

1 Like

Hello @zhangjing,
Please let me know if you need any help!! Flux is hard to wrap your head around at first, but it’s very powerful once you adjust your thinking.

thanks a lot .I have solved this using flux. the url “GitHub - influxdata/influxdb-client-csharp: InfluxDB 2.0 C# Client” giving me the example.

1 Like