TDengine/docs/examples/python/query_native.py

21 lines
622 B
Python
Raw Normal View History

2024-08-02 08:20:50 +00:00
import taos
2024-08-12 06:13:31 +00:00
host="localhost"
port=6030
2024-08-02 08:20:50 +00:00
conn = None
try:
2024-08-12 06:13:31 +00:00
conn = taos.connect(host=host,
port=port,
2024-08-02 08:20:50 +00:00
user="root",
password="taosdata")
result = conn.query("SELECT ts, current, location FROM power.meters limit 100")
# Get data from result as list of tuple
data = result.fetch_all()
for row in data:
2024-08-12 06:13:31 +00:00
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
2024-08-02 08:20:50 +00:00
except Exception as err:
2024-08-12 11:33:50 +00:00
print(f"Failed to query data from power.meters, db addr:{host}:{port} ; ErrMessage:{err}")
2024-08-02 08:20:50 +00:00
finally:
if conn:
conn.close()