Using clickhouse-connect
I am querying a table to get a timestamp:
import clickhouse_connect
client = clickhouse_connect.get_client(
host=CLICKHOUSE_CLOUD_HOSTNAME,
username=CLICKHOUSE_CLOUD_USER,
password=CLICKHOUSE_CLOUD_PASSWORD
)
q0 = "SELECT DISTINCT timestamp FROM mydb.mytable"
r0 = list(client.query(q).named_results())
print(r0)
"""
Getting the below results:
[{'timestamp': datetime.datetime(2024, 9, 1, 0, 0, 25, 26208, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)}, {'timestamp': datetime.datetime(2024, 9, 1, 0, 0, 25, 27033, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)}, {'timestamp': datetime.datetime(2024, 9, 1, 0, 0, 25, 27597, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)}]
"""
Now I want to query the DB to get all the data for the first timestamp here:
dtt = r0[0]['timestamp']
parameters = {"v1":dtt, "query_tz":"UTC"}
# also tried: parameters = {"v1":dtt, "query_tz":"UTC"}
# also tried: parameters = {"v1":dtt.astimezone(pytz.utc), "query_tz":"UTC"}
# also tried: parameters = {"v1":dtt.astimezone(pytz.utc)}
q1 = "SELECT * FROM mydb.mytable WHERE timestamp = {v1:DateTime}"
r1 = client.query(qq, parameters=parameters)
print(list(r1.named_results()))
# result is always empty: []
But i cannot get the row, and I tried different versions of the timestamp.
The type of the timestamp column in the table is DateTime64(6)
Useful for reproduction:
- python: 3.11
- clickhouse-connect: 0.7.18
- OS: Windows
3