pythonpython-3.xdatabaseinfluxdbinfluxdb-python

"Error parsing query: missing parameter" InfluxDB Python API query while using parameters


I have a UDP InfluxDB connection:

client = InfluxDBClient(host='localhost', database='adatabase', use_udp=True, udp_port=1234)

Then, I have the following function:

    def getData(self, measurement, field="*", tag="", timeStart=0, timeEnd=0):
    parameters = {"selectedMeasurement": measurement,
                  "selectedField": field}
    print(parameters)
    result = self.client.query('SELECT LAST($selectedField) FROM $selectedMeasurement;', params=parameters)
    print(list(result.get_points()))
    return list(result.get_points())

But I get the following error:

influxdb.exceptions.InfluxDBClientError: 400: {"error":"error parsing query: missing parameter: selectedField"}

I don't understand where the problem is. Also tried with bind_params. I use hardcoded fields and measurements, the code works fine.


Solution

  • Influxdb allows to use bind_params ($variable) in the WHERE statement, not in SELECT.

    Influxdb Docs - Bind Parameter