0

I'm trying this query from Grafana and it works perfectly: SELECT * FROM "x" WHERE time > '2020-03-31' AND time < '2020-04-02'

The problem is, in python I have to format the query as a string, and I run into the following problems:

1) if I use double quotes around the whole line, I get invalid syntax because the FROM field requires double quotes already (and I get influxdb.exceptions.InfluxDBClientError: 400 if I try to use single quotes around the FROM field)

2) if I use single quotes around the whole line, it sees the dates as int and returns invalid syntax

3) if I don't use quotes at all around the whole line, I get invalid syntax

4) if I use single double quotes around the dates it returns 0 elements

5) if I use single quotes and wrap dates with str() I get either 0 elements or syntax error depending if still use quotes inside the str() or not

6) if I try to wrap the whole line in str() I get syntax error

I tried all of those with both: result = client.query(q, chunked=True).get_points() result = list(client.query(q, chunked=True).get_points())

I'd prefer to use the list if possible. InfluxDB 1.7.9, Influx Python Client 5.2.3, Python 3.7, MacOs 10.12.6

1
  • Fixed using: "SELECT * FROM \"x\" WHERE time > '2020-03-31' AND time < '2020-04-02'" Commented Apr 1, 2020 at 22:49

1 Answer 1

0

I'm not sure it can work but you could try to use triple quotes. The questions of mixing single and double quotes was asked here.

Example:

print(""" I'm "Bob" """)

Use spaces around the triple space otherwise you'll get an error.

Sign up to request clarification or add additional context in comments.

1 Comment

Already fixed using \"x\" and double quotes around the whole thing, see comments above. Thank you anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.