taosdata / taos-connector-python

TDengine connector for Python
https://www.taosdata.com/cn/documentation/connector#python
MIT License
48 stars 14 forks source link

Table name is case sensitive in parameter binding statement - WebSocket client #260

Open jond01 opened 1 month ago

jond01 commented 1 month ago

I use the taosws client and write data with parameter binding. Setting the table name fails when the name includes uppercase letters.

from datetime import datetime, timezone

import taosws

TABLE_NAME = "lowUP"

conn = taosws.connect("taosws://root:taosdata@localhost:6041")
conn.execute("CREATE DATABASE IF NOT EXISTS t0;")
conn.execute("USE t0;")

conn.execute(f"CREATE TABLE {TABLE_NAME} (time TIMESTAMP, val INT);")
print(f'{list(conn.query("SHOW TABLES;")) = }')

# Standard insertion
conn.execute(f"INSERT INTO {TABLE_NAME} VALUES (now(), 0);")

# Select the data
print(f'{list(conn.query(f"SELECT * FROM {TABLE_NAME};")) =}')

# Parameter bound insertion
stmt = conn.statement()
stmt.prepare("INSERT INTO ? VALUES (?, ?);")
stmt.set_tbname(TABLE_NAME)  # <-- this line errors

stmt.bind_param(
    [
        taosws.millis_timestamps_to_column([int(datetime.now(tz=timezone.utc).timestamp() * 1000)]),
        taosws.ints_to_column([2]),
    ]
)

stmt.add_batch()
stmt.execute()

print(f'{list(conn.query(f"SELECT * FROM {TABLE_NAME};")) =}')

Error:

ProgrammingError: [0x2603] Internal error: `Table does not exist`

When TABLE_NAME is lowercase only, e.g. "low", the snippet passes.

I expect it to work since TDEngine table names are case-insensitive:

Names are case insensitive.

https://docs.tdengine.com/reference/taos-sql/limit/#restrictions-of-tablecolumn-names

I found that escaping the table name with `` works:

TABLE_NAME = "`lowUP`"

Still, the current behavior is unexpected.