Repository navigation
Open
Labels
bugdata-typesArea: type names, value encoding and decoding, row mapping, data formatsjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)
Description
Description
When running a prepared statement with COALESCE and a date, the execution fails due to type.
Am not entirely sure whether it's an issue with the JDBC driver (which serializes the date as a String in PreparedStatementImpl#encodeObject - nothing wrong with that) or the server (which should deserialize it with the proper type, or COALESCE which should handle types better - see ClickHouse/ClickHouse#57292 , although most other databases handle this use case).
Steps to reproduce
See the code below.
Error Log or Exception StackTrace
Caused by: com.clickhouse.client.api.ServerException: Code: 386. DB::Exception: There is no supertype for types Date32, String because some of them are String/FixedString/Enum and some of them are not: In scope SELECT COALESCE(date, '2025-12-31') FROM test_local_date. (NO_COMMON_TYPE) (version 25.8.7.3 (official build))
at com.clickhouse.client.api.internal.HttpAPIClientHelper.readError(HttpAPIClientHelper.java:403)
Expected Behaviour
The query should return without error.
Code Example
@Test
void required_testJdbcWithLocalDate() throws Exception {
final String url = "jdbc:ch://localhost:" + SERVER.getFirstMappedPort();
final Properties info = new Properties();
info.put("user", SERVER.getClickhouseUser());
info.put("password", SERVER.getClickhousePassword());
try (final Connection conn = DriverManager.getConnection(url, info)) {
conn.prepareStatement("CREATE TABLE test_local_date"
+ " (id Int64, date Nullable(Date32)) ENGINE = MergeTree() ORDER BY id").execute();
conn.prepareStatement("INSERT INTO test_local_date VALUES (1, null)").execute();
try (final PreparedStatement preparedStatement = conn.prepareStatement("SELECT COALESCE(date, ?) FROM test_local_date")) {
preparedStatement.setObject(1, LocalDate.of(2025, 12, 31));
preparedStatement.executeQuery();
}
}
}Configuration
Client Configuration
Environment
- Cloud
- Client version: clickhouse-jdbc 0.9.4
- Language version:
- OS:
ClickHouse Server
- ClickHouse Server version: 25.8.7.3
Metadata
Metadata
Assignees
Labels
bugdata-typesArea: type names, value encoding and decoding, row mapping, data formatsjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)
Activity
chernser commentedon Dec 3, 2025
Good day, @jnd77 !
Thank you for reporting!
This is the problem in how to represent values like DateTime in text format so it is suitable for functions expecting string and for functions that expect certain type. You may use
com.clickhouse.jdbc.PreparedStatementImpl#setObject(int, java.lang.Object, java.sql.SQLType)so driver will addCAST.I agree it is counter-intuitive to pass Date object and get string on server side. There is more simple example
SELECT ?where it will become string and we might fail to returnDate.We are working on this .
polyglotAI-bot commentedon Nov 28, 2026
Recommendation: Keep open — maintainer decision
A maintainer decides how jdbc-v2 sends the type of a
?value: the CAST of 0.9.1–0.9.6 broke other queries (#2701). The CAST workaround in the thread does not work since v0.9.7 (#2710).Date32,LocalDateparameters)main: Reproduced on main — the issue's error on ClickHouse 25.8; from 26.1 no error, but the result isVariant(Date32, String)with aStringvalue.docs/features.md:128documents the quoted text form); behind a new option it does not break.parseDateTimeBestEffort(?).COALESCE(date, toDate32(?))returns aDate32on ClickHouse 25.8 and 26.11.Analysis:
PreparedStatementImpl.java:774-775writes aLocalDateas the text literal'2025-12-31', so the server getsCOALESCE(Nullable(Date32), String). ClickHouse 25.8 has no common type for these; from 26.1,use_variant_as_common_typeis on by default and gives aVariant. Since v0.9.7,setObject(int, Object, SQLType)(lines 285-289) only checks the type and adds no CAST.Reproduction: complete program and output
Changed from the issue's steps: the test body in a
main, with its ownDROP TABLE; added asetObject(…, JDBCType.DATE)case, atoDate32(?)case, and the result type of each case.Output on
main(8480ca001), ClickHouse 25.8.33.6:Output on
main(8480ca001), ClickHouse 26.11.4.11:Automated triage by Polyglot AI. A maintainer makes the final decision.