Repository navigation
Labels
bugjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)queriesArea: how the client builds and runs statements (parameters, quoting, batches)sql-parserDetail: the SQL parser of the JDBC driver (v1 and v2)
Milestone
Description
Description
When using keywords (I think?) as aliases without AS keyword and without quoting, then the JDBC driver fails later on when trying to bind variables. This is due to the JDBC driver's parser failing on the query, despite the query being accepted by the server.
Steps to reproduce
try (PreparedStatement s = connection.prepareStatement(
"""
select
1 table
where
1 = ?
""")) {
s.setInt(1, 1);
try (ResultSet rs = s.executeQuery()) {
while (rs.next())
println(rs.getInt(1));
}
}Error Log or Exception StackTrace
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.clickhouse.jdbc.PreparedStatementImpl.setInt(PreparedStatementImpl.java:180)
at org.jooq.testscripts.JDBC.main(JDBC.java:46)
Expected Behaviour
The query should work and print 1, since the server also accepts the query as being valid. E.g. this static statement works just fine:
try (Statement s = connection.createStatement()) {
try (ResultSet rs = s.executeQuery(
"""
select
1 table
where
1 = 1
"""
)) {
while (rs.next())
println(rs.getInt(1));
}
}Alternatively, if these keyword-style aliases are really not supported, then there should be a more explicit error message, but I think they should be supported, since the server supports this syntax.
Workarounds
Use the AS keyword for aliasing
try (PreparedStatement s = connection.prepareStatement(
"""
select
1 as table
where
1 = ?
""")) {
s.setInt(1, 1);
try (ResultSet rs = s.executeQuery()) {
while (rs.next())
println(rs.getInt(1));
}
}Quote the identifier
try (PreparedStatement s = connection.prepareStatement(
"""
select
1 "table"
where
1 = ?
""")) {
s.setInt(1, 1);
try (ResultSet rs = s.executeQuery()) {
while (rs.next())
println(rs.getInt(1));
}
}Configuration
Environment
- Client version:
com.clickhouse:clickhouse-jdbc:0.9.2 - Language version: OpenJDK Runtime Environment Temurin-21.0.7+6 (build 21.0.7+6-LTS)
- OS: Microsoft Windows [Version 10.0.26100.4946]
ClickHouse Server
- ClickHouse Server version: 25.4.4.25
Metadata
Metadata
Assignees
Labels
bugjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)queriesArea: how the client builds and runs statements (parameters, quoting, batches)sql-parserDetail: the SQL parser of the JDBC driver (v1 and v2)
Activity
barisinanc commentedon Sep 10, 2025
I have tried 0.9.1 and 0.9.2 both versions have same problems when updating and deleting records. Is there any version that does not give that error.
lukaseder commentedon Sep 10, 2025
@barisinanc I upgraded from 0.7.0 to 0.9.0/0.9.2 when encountering this error, so 0.7.0 shouldn't have these issues (and tons of others that I've reported recently). I think 0.9.x is not ready for production usage, the parser causing these problems appears to be in an experimental state, see also:
barisinanc commentedon Sep 10, 2025
Thank you @lukaseder, We are using spring boot and spring data, I have tried 0.8.5 but encountered a lot more errors. I will try 0.7.0 and report back.
chernser commentedon Oct 27, 2025
Verified with
com.clickhouse.jdbc.internal.BaseSqlParserFacadeTest#testStatementWithoutResultSetDP