resolver101
resolver101

Reputation: 2255

influxdb : how do I filter by a field > than 4

I have the following query which shows all records:

SELECT "ApparentPower" FROM "machine01" WHERE "pin_no" = 'pin 2 ' AND $timeFilter;

I want to filter by field "ApparentPower" and only show values greater than 10. How do i do this?

If i run the query SELECT "ApparentPower" FROM "machine01" WHERE "pin_no" = 'pin 2 ' AND $timeFilter AND "ApparentPower" > 10; i get no values returned even though there are values greater than 10.

Also if i run the query SELECT "ApparentPower" FROM "machine01" WHERE "pin_no" = 'pin 2 ' AND $timeFilter AND "ApparentPower" < 10; i get no values returned again.

However if i run the query SELECT "ApparentPower" FROM "machine01" WHERE "pin_no" = 'pin 2 ' AND $timeFilter AND "ApparentPower" != 10; i get all values returned.

I've checked the version of influx im running using the command curl -sL -I localhost:8086/ping:

HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: f4132538-7129-11eb-b770-000000000000
X-Influxdb-Version: 1.1.1
Date: Wed, 17 Feb 2021 14:10:56 GMT

Upvotes: 0

Views: 1738

Answers (1)

cidermole
cidermole

Reputation: 6078

Likely, the "ApparentPower" field is written to InfluxDB as a string.

You can verify this using: SHOW FIELD KEYS FROM "machine01"

A field must be written as integer or float in order to be compared with <

Changing the data type:

You cannot change the data type of an existing measurement field, but you can:

  • write to a different field name,
  • remove the measurement using DROP MEASUREMENT machine01,
  • if you have sharding enabled, wait until writes go to the next shard.

Upvotes: 2

Related Questions