deepsneakers
deepsneakers

Reputation: 1

How to bind parameters to InfluxDB Python client query

How can I bind query parameters to an InfluxDB query using the Python client?

For example, I want the results of a query filtered by the InfluxDb tag "my_tag": some_id=5 SELECT * FROM "foobar" WHERE ("my_tag"=some_id);

client = InfluxDBClient(host=my_host,port=my_port)
client.switch_database(database=my_database)

def get_results_by_id(my_id):
    results = client.query(
        query='SELECT * FROM "foobar" WHERE ("my_tag" = id)',
        params={"id": my_id}
    )
    ...
)

Getting zero results with this. Obviously, I can just use a string formatter, but there must be a way to do it with the Influx API.

Upvotes: 0

Views: 2475

Answers (1)

hoang pham
hoang pham

Reputation: 81

client = InfluxDBClient(host=my_host,port=my_port)
client.switch_database(database=my_database)

def get_results_by_id(my_id):
    results = client.query(
        query='SELECT * FROM foobar WHERE my_tag=$my_tag;',
        params={"my_tag": my_id}
    )
    ...
)

Upvotes: 3

Related Questions