Hi guys a quick one I hope, but I’m starting to feel like an idiot.
I have found similar threads but not being a programmer I don’t quite understand the answers.
I need to query like this.
SELECT “sensor” FROM “librenms20”.“autogen”.“wireless-sensor” WHERE time > now() - 12h AND “sensor_descr”=‘Tx\ Power’ AND “hostname”='172.16.2.6’
But apparently there is a problem with the backslash. and I dont have control over this because this is how LibreNMS exports it to influx.
Could you guys just help me create the query correctly?
I have slight idea of whats going on but not quite as I use to do a little work with SQL server many years back but I cant remember anything from back then besides that using spaces and characters in a string is a bad idea and that one usually need to come up with a work around either programmatically or by query
Hi Arjun,
A backslash is often used as an “escape character”, which tells your software that the next character in the sequence should have a special interpretation, and we use it for that purpose in InfluxQL.
For example, if your programming language defines a string as a series of characters enclosed in double quotes:
"string"
and you tried to create a string that contained a double quote:
"simon says, "stand up""
the language would interpret the second double quote as the end of the string. In order to get around this problem you could use an escape character to indicate that the double quotes within the string should be interpreted differently, in this case as part of the string instead of the end of the string, as follows:
"simon says, \"stand up\""
It can get a little hard to read, but these are the sacrifices we make for our computers.
In your query, InfluxDB is interpreting the \P
part of the Tx\ Power
string as a single, special character. In order to treat the backslash as a part of the string, you will need to escape it using another backslash, like this: \\
.
Try this query instead:
SELECT “sensor” FROM “librenms20”.“autogen”.“wireless-sensor” WHERE time > now() - 12h AND “sensor_descr”=‘Tx\\ Power’ AND “hostname”='172.16.2.6’