TDengine/docs/examples/python/insert_ws.py

28 lines
913 B
Python
Raw Normal View History

import taosws
2024-08-02 07:14:08 +00:00
conn = None
2024-08-12 06:13:31 +00:00
host="localhost"
port=6041
2024-08-02 07:14:08 +00:00
try:
conn = taosws.connect(user="root",
password="taosdata",
2024-08-12 06:13:31 +00:00
host=host,
port=port)
2024-08-02 07:14:08 +00:00
sql = """
INSERT INTO
power.d1001 USING power.meters (groupid, location) TAGS(2, 'California.SanFrancisco')
VALUES (NOW + 1a, 10.30000, 219, 0.31000)
(NOW + 2a, 12.60000, 218, 0.33000) (NOW + 3a, 12.30000, 221, 0.31000)
power.d1002 USING power.meters (groupid, location) TAGS(3, 'California.SanFrancisco')
VALUES (NOW + 1a, 10.30000, 218, 0.25000)
"""
2024-08-03 10:04:12 +00:00
affectedRows = conn.execute(sql)
2024-08-12 06:13:31 +00:00
print(f"Successfully inserted {affectedRows} rows to power.meters.")
2024-08-02 07:14:08 +00:00
except Exception as err:
2024-08-12 06:13:31 +00:00
print(f"Failed to insert data to power.meters, db addr:{host}:{port} ; err:{err}")
2024-08-02 07:14:08 +00:00
finally:
if conn:
conn.close()