Parsing issue while use influx shell

  1. Works well but same being use on influx shell it wont work and has some parsing issue

cd /opt/monitoring_tools/influxdb-1.2.4-1/usr/bin/
./influx -port 17053

use timedb
Using database timedb

select MEAN(“executiontime”) from “timestats” where ((“host”=‘abc123’ or “host”=‘abc124’) AND (time >= ‘2018-04-24T18:15:00Z’ AND time <= ‘2018-04-26T19:45:00Z’ )) group by time(12h)
name: timestats
time mean


1524571200000000000 148393271.33333334
1524614400000000000 23449218.529411765
1524657600000000000 1257.17
1524700800000000000
1524744000000000000

  1. Issue on influx shell
    $ influx -execute ‘select MEAN(“executiontime”) from “timestats” where ((“host”=‘abc123’ or “host”=‘abc124’) AND (time >= ‘2018-04-24T18:15:00Z’ AND time <= ‘2018-04-26T19:45:00Z’ )) group by time(12h)’
    ERR: error parsing query: invalid duration
    Warning: It is possible this error is due to not setting a database.
    Please set a database with the command “use ”.
    error parsing query: invalid duration
    $

If have the same issue. Did you manage to solve it?

My workaround is using now(). Alternatively you can also use epoch time. Look here for syntax: Data Exploration | InfluxData Documentation Archive

But I think it’s a workaround that should not be necessary. It should just be able to recognize the time strings. I think it might a problem of how influx parses the command-string to execute.

The issue @vtom was having is described in the error message,

Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use ".

The command was executed from the shell without specifying a database.

It is possible to use strings in RFC 3339 format in your queries. For example, I have three data points with timestamps in the last hour:

> select * from m where time > now()-1h
name: m
time                f1 tag
----                -- ---
1530092703077893900 42 tag1
1530092710995001700 44 tag1
1530092748280806100 46 tag1
> 

I can run the following command to select all values more recent than a given time:

> select * from m where time > '2018-06-27T09:45:30Z'
name: m
time                f1 tag
----                -- ---
1530092748280806100 46 tag1
> 

Or from the command line:

$ influx -execute "select * from m where time > '2018-06-27T09:45:30Z'" -database="test1"
name: m
time                f1 tag
----                -- ---
1530092748280806100 46 tag1

In order to control the formatting of the output, I can run precision rfc3339 within the interactive CLI, or pass the flag -precision="rfc3339" when executing a query from the command line directly.

The problem for me was not running the query without specifying the database. The problem was that Influx finished reading the execution String just before the first timestamp when writing in this format:

influx -execute 'SELECT sum("field") as "field" INTO "database"."retention"."measurement" FROM "database"."retention".measurement" WHERE time >= '2018-05-31T00:00:00Z' AND time <= '2018-06-23T00:00:00Z' GROUP BY time(1d), *'

Because it thinks the second ' is closing the execution String.

It works with escaping and switching the ' and ":
influx -execute "SELECT sum(\"field\") as \"field\" INTO \"database\".\"retention\".\"measurement\" FROM \"database\".\"retention\".\"measurement\" WHERE time >= '2018-05-31T00:00:00Z' AND time <= '2018-06-23T00:00:00Z' GROUP BY time(1d), *"

Closing this topic as “Parsing issue while use influx shell” it is too generic.