-
Notifications
You must be signed in to change notification settings - Fork 603
Open
Labels
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