housepower / ClickHouse-Native-JDBC

ClickHouse Native Protocol JDBC implementation
https://housepower.github.io/ClickHouse-Native-JDBC/
Apache License 2.0
523 stars 145 forks source link

sql statement generate: how to use clickhouse function in where condition #440

Closed ZzzhouYu closed 1 year ago

ZzzhouYu commented 1 year ago

I want to implement something like this: sql:
select * from database.table where timeField >= ? parameters: toDateTime64('2023-06-19 00:40:00.000', 0, 'Asia/Shanghai') like this: select * from database.table where timeField >= toDateTime64('2023-06-19 00:40:00.000', 0, 'Asia/Shanghai') i set parameters to String.

but, debug code, in AbstractPreparedStatement , when parameter instanceof String, assembleQuotedParameter function add ' between the parameter.

the sql become this: select * from database.table where timeField >= 'toDateTime64('2023-06-19 00:40:00.000', 0, 'Asia/Shanghai')'

what should i do?

ZzzhouYu commented 1 year ago

i know this. make timeField >= toDateTime(?, 0, 'Asia/Shanghai') to statement. '2023-06-19 00:40:00.000' to parameters. like this:

statement = connection.prepareStatement("timeField >= toDateTime(?, 0, 'Asia/Shanghai')");
statement.setString("2023-06-19 00:40:00.000");