Search code examples
influxdb

InfluxDB - Including multiple values in where clause based on tags


I'm trying to query data based on tag values. Is it possible to include multiple queries in the where clause . I could not find an operator similar to the IN operator in SQL.

select * from students where rollNumber='1' limit 10

students is the measurement and rollNumber is a tag. I want include multiple values of rollNumber in the query.

Any suggestions to solve the problem?


Solution

  • InfluxDB does not have IN operator, however it supports Go-lang regular expressions in WHERE clause for fields and tags. Regular expressions are enclosed with / and require adding ~ after comparison operator:

    select * from students where rollNumber =~ /1|2|3/ limit 10
    

    This will return 10 students, where rollNumber tag contains 1 or 2 or 3.

    For a precise match the following should work:

    select * from students where rollNumber =~ /^[1|2|3]$/ limit 10
    

    Note: In case of filtering fields, if the type of fields is not string, regex will not work...

    But as noted in the comments, using OR operator with explicit comparison should work better, as tag index can be used for more efficient querying.