Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Documentation of query format using variables #701

Open
Rbain2 opened this issue Apr 11, 2019 · 2 comments
Open

Documentation of query format using variables #701

Rbain2 opened this issue Apr 11, 2019 · 2 comments

Comments

@Rbain2
Copy link

Rbain2 commented Apr 11, 2019

Hi

I spent a long time trying to find a format of query with variable inputs. I eventually found the following which allows parameters in the select statement.
res = influx.query("""
select * from program_event_name
where account = '%s'
and region = '%s'
order by time desc limit 1""" % (
account['name'], region))

at the web site below which includes other influxdb code examples.
https://www.programcreek.com/python/example/107755/influxdb.InfluxDBClient

. This format worked perfectly. I would like to see this or a similar example of parameterized query included in the basic documentation of the library as I believe it gives a lot of extra flexibility which is not obvious to me from the existing documentation and could save developers a lot of time

@clslgrnc
Copy link
Contributor

I'd argue against including this kind of example, not only is it not a query with variables (this is string formatting, the formatted string is passed to influxdb-python without parameters) but more importantly this is a potentially dangerous pattern as remarked by #316 and #603 and as I explained here.

You should use bind parameters instead, they will be available and documented in the next release.
Or you can already use:

params = {"account": account['name'], "region": region}

query('select * from program_event_name '
      'where account = $account '
      'and region = $region '
      'order by time desc limit 1',
      params={"params":json.dumps(params)}
)

@Rbain2
Copy link
Author

Rbain2 commented Apr 17, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants