查询数据库潮

问题描述 投票:0回答:2

我有这样的代码来查询数据库涌入,但它是不工作的。这里是Python代码。

import os

from influxdb import InfluxDBClient

username = u'{}'.format(os.environ['INFLUXDB_USERNAME'])
password = u'{}'.format(os.environ['INFLUXDB_PASSWORD'])

client = InfluxDBClient(host='127.0.0.1', port=8086, database='data',
                        username=username, password=password)

result = client.query("SELECT P_askbid_midprice1 FROM 'DCIX_OB' WHERE time > '2018-01-01';")

我得到了以下错误,但目前还不清楚如何解决上面的代码。如果我直接从influxdb查询与SELECT P_askbid_midprice1 FROM 'DCIX_OB' WHERE time > '2018-01-01';庆典它的工作完美的罚款。

    Press ENTER or type command to continue
    Traceback (most recent call last):
      File "graph_influxdb.py", line 11, in <module>
        result = client.query("SELECT P_askbid_midprice1 FROM 'DCIX_OB' WHERE time > '2018-01-01';")


  File "/home/ubuntu/.local/lib/python3.5/site-packages/influxdb/client.py", line 394, in query
    expected_response_code=expected_response_code
  File "/home/ubuntu/.local/lib/python3.5/site-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 31"}

我怎样才能解决这个问题?

python influxdb influxdb-python
2个回答
2
投票

结果= client.query( “选择P_askbid_midprice1 FROM DCIX_OB WHERE时间> '2018年1月1日'”)

这应该工作


0
投票

您可能能够使用Pinform这是某种形式的ORM / OSTM(对象的时间序列映射)为InfluxDB的。

它可以与设计模式,构建正常或聚集查询帮助。

cli.get_fields_as_series(OHLC,
    field_aggregations={'close': [AggregationMode.MEAN]},
    tags={'symbol': 'AAPL'},
    time_range=(start_datetime, end_datetime),
    group_by_time_interval='10d')

免责声明:我是这个库的作者

© www.soinside.com 2019 - 2024. All rights reserved.