jma
jma

Reputation: 3779

influxdb: selecting values containing quotes

I have some tag values that were unfortunately sent with quotes in them:

> SELECT count("count") FROM "railswebapp"
  WHERE "auth_method" =~ /facebook/ GROUP BY "auth_method"
name: railswebapp
tags: auth_method=\"facebook\"
time count
---- -----
0    4

name: railswebapp
tags: auth_method=facebook
time count
---- -----
0    2632

>

Alas, querying for the "facebook" series is harder than I expect:

> SELECT "count" FROM "railswebapp"
  WHERE "auth_method" = '\"facebook\"'
> 

This work-around works but surely I can do better. Any suggestions?

> SELECT count("count") FROM "railswebapp"
  WHERE "auth_method" =~ /facebook/
    AND "auth_method" != 'facebook'
  GROUP BY "auth_method"
name: railswebapp
tags: auth_method=\"facebook\"
time count
---- -----
0    4

> SELECT count FROM "railswebapp"
  WHERE "auth_method" =~ /facebook/
    AND "auth_method" != 'facebook'
  GROUP BY "auth_method"

name: railswebapp
tags: auth_method=\"facebook\"
time                count
----                -----
152412927875202308  1
152412927882740082  1
1524130761574200511 1
1524134859852346944 1

> 

(Note: influx doesn't support line breaks in queries: they just make this question more readable.)

Upvotes: 1

Views: 1887

Answers (2)

user2664585
user2664585

Reputation: 21

When dealing with single quotes I found this to work;

select * from some_measurement where some_tag =~ /\'foo\'/;

Upvotes: 0

Sufiyan Ghori
Sufiyan Ghori

Reputation: 18743

It is mentioned on influxdb documentation to not double or single quote measurement names, tag keys, tag values, and field keys.

Here is how quoting are handled,

  • Do not double or single quote measurement names, tag keys, tag values, and field keys. It is valid Line Protocol but InfluxDB assumes that the quotes are part of the name.
  • Never single quote field values (even if they’re strings!). It’s also not valid Line Protocol.
  • Do not double quote field values that are floats, integers, or Booleans. InfluxDB will assume that those values are strings.

It also mentioned ,

For string field values use a backslash character \ to escape:

Example,

Inserting data with tag-value containing double-quote,

INSERT cpu,host="x" value=10

Querying,

select * from cpu where host = '\"x\"'

Output,

name: cpu
time                host value
----                ---- -----
1530754262442056777 "x"  10

Upvotes: 1

Related Questions