Reputation: 417
With influxdb, it is possible to cast a float field to integer with following syntax:
SELECT "water_level"::integer FROM "h2o_feet" LIMIT 4
currently, our "water_level" is aready an integer, but, for some reason, we need to divide all values per 10.
SELECT water_level*0.1 as water_level INTO "h2o_feet" FROM "h2o_feet"
Unfortunately, water_level*0.1 is now a float (so we get a field type conflict during the update : field type already exists as type integer)
We don't want to convert the field to float. we need to leave it as an integer (I now we will lose some precision)
we tried following syntaxes :
round(water_level*0.1)
trunc(water_level*0.1)
(water_level*0.1)::integer
But none of these works. "Round" and "Trunc" return a float, and last syntax is incorrect.
So, how to cast to integer after any kind of mathematical operation?
Upvotes: 0
Views: 1642
Reputation: 466
You can use subqueries to achieve this. Can you try the below query?
SELECT water_level::integer INTO "h2o_feet" from (SELECT water_level*0.1 as water_level FROM "h2o_feet");
Hope this works
Upvotes: 2