Jeremie
Jeremie

Reputation: 435

Struggling with SQL line

I am struggling with the SQL-like line, and I just don't know how to fix it.

query = "SELECT P_askbid_midprice1, Label1 FROM 'DCIX_OB' WHERE time >= '2018-02-16T09:00:00Z' and time <= '2018-02-16T16:00:00' "

I got the following error with the previous line :

Traceback (most recent call last):
  File "graph_influxdb.py", line 53, in <module>
    read_data(length='5min')
  File "graph_influxdb.py", line 29, in read_data
    result = client.query(query)
  File "/usr/local/lib/python3.6/dist-packages/influxdb/client.py", line 394, in query
    expected_response_code=expected_response_code
  File "/usr/local/lib/python3.6/dist-packages/influxdb/client.py", line 271, in request
    raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"error parsing query: found DCIX_OB, expected identifier at line 1, char 39"}

How can I fix that issue?

Upvotes: 0

Views: 67

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170859

Single quote string values (for example, tag values) but do not single quote identifiers (database names, retention policy names, user names, measurement names, tag keys, and field keys).

Double quote identifiers if they start with a digit, contain characters other than [A-z,0-9,_], or if they are an InfluxQL keyword. Double quotes are not required for identifiers if they don’t fall into one of those categories but we recommend double quoting them anyway.

I.e. use FROM "DCIX_OB" (FROM DCIX_OB is also legal but not recommended).

Upvotes: 1

Related Questions