TDengine/docs/examples/python/reqid_native.py

25 lines
625 B
Python
Raw Normal View History

2024-08-02 18:51:12 +00:00
import taos
conn = None
2024-08-12 12:56:20 +00:00
reqId = 3
2024-08-12 06:13:31 +00:00
host="localhost"
port=6030
2024-08-02 18:51:12 +00:00
try:
2024-08-12 06:13:31 +00:00
conn = taos.connect(host=host,
port=port,
2024-08-02 18:51:12 +00:00
user="root",
password="taosdata")
2024-08-12 06:13:31 +00:00
result = conn.query("SELECT ts, current, location FROM power.meters limit 100", reqId)
2024-08-02 18:51:12 +00:00
# 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 18:51:12 +00:00
except Exception as err:
2024-08-14 08:25:22 +00:00
print(f"Failed to execute sql with reqId:{reqId}, ErrMessage:{err}")
2024-08-12 06:13:31 +00:00
2024-08-02 18:51:12 +00:00
finally:
if conn:
2024-08-12 12:56:20 +00:00
conn.close()