我设置了Apache Phoenix数据库,我正在尝试使用Python和PhoenixDb插件进行查询。
我有一个包含以下行的表:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| PK | did | sensorid | sensor_timestamp | EXTRA_LEVEL | EXTRA_SCALE | EXTRA_HEALTH | EXTRA_STATUS | EXTRA_PLUGGED | EXTRA_PRESENT | EXTRA_VOLTAGE | level_percent | temperature_C | EXTRA_TECHNOLOGY | EXTRA_TEMPERATURE |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
当我尝试使用phoenixdb查询它时,它会遗漏1行,但我没有收到任何错误。
我的查询代码是:
import phoenixdb
connection = phoenixdb.connect(<url>)
cursor = connection.cursor()
query = """select PK,"did", "sensorid", "sensor_timestamp", {3}
from "sensor_data"
where "did"='{0}'
and "sensorid" = '{1}'
and "sensor_timestamp" > '{2}'
order by "sensor_timestamp"
limit 10""".format(357139052213522, 902, 1463163952256, '"EXTRA_LEVEL", "EXTRA_SCALE", "EXTRA_HEALTH", ' \
'"EXTRA_STATUS" "EXTRA_PLUGGED", "EXTRA_PRESENT", ' \
'"EXTRA_VOLTAGE", "level_percent", "temperature_C", ' \
'"EXTRA_TECHNOLOGY","EXTRA_TEMPERATURE"')
cursor.execute(query)
rows = cursor.fetchall()
for row in rows:
print(row)
我的输出是:
['357139052213522_1486731821342_902', '357139052213522', '902', '1486731821342', '64', '100', '2', '2', 'true', '3990', '64.0', '25.0', 'Li-ion', '257']
通过计算,我发现有一个项目丢失了。有没有人知道这可能是什么原因?
答案 0 :(得分:0)
好。这是一个非常愚蠢的错误。我发现我在查询中遗漏了一个逗号。修复解决了这一切:
query = """select PK,"did", "sensorid", "sensor_timestamp", {3}
from "sensor_data"
where "did"='{0}'
and "sensorid" = '{1}'
and "sensor_timestamp" > '{2}'
order by "sensor_timestamp"
limit 10""".format(357139052213522, 902, 1463163952256, '"EXTRA_LEVEL", "EXTRA_SCALE", "EXTRA_HEALTH", ' \
'"EXTRA_STATUS", "EXTRA_PLUGGED", "EXTRA_PRESENT", ' \
'"EXTRA_VOLTAGE", "level_percent", "temperature_C", ' \
'"EXTRA_TECHNOLOGY","EXTRA_TEMPERATURE"')