-
Notifications
You must be signed in to change notification settings - Fork 614
Closed
Description
Description
when attempting to make a union select statement of a form similar to:
SELECT *
FROM test_table
UNION DISTINCT
SELECT *
FROM test_table
Steps to reproduce
- make a prepared statement using the above query
- executeQuery
Error Log or Exception StackTrace
line 1:31 mismatched input 'DISTINCT' expecting ALL
Expected Behaviour
a union of distinct elements is performed on the given select statements. (it looks like the antlr grammar specifically defines a union statement as 2 selects UNION ALL)
Code Example
String sql = "SELECT * FROM " + TABLE_NAME + " UNION DISTINCT SELECT * FROM " + TABLE_NAME;
// try to get all results with a union distinct
try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
try (Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
System.out.println("id: " + rs.getInt("id") + ", Name: " + rs.getString("NameCol") + ", Attributes: " + rs.getString("MapCol") + ", TimeStamp: " + rs.getString("TimeCol") + ", Value: " + rs.getDouble("Value"));
}
}
}Configuration
tested with a local docker container at clickhouse:8123
Environment
- Client version: 0.9.0
- Language version: Java 17.0.6
- OS: CentOS 8 (also seen on Rocky9)
ClickHouse Server
- ClickHouse Server version: 25.5.2
- ClickHouse Server non-default settings, if any: N/A
CREATE TABLEstatements for tables involved:
CREATE TABLE IF NOT EXISTS test_table (
id UInt64,
NameCol String,
MapCol Map(LowCardinality(String), String),
TimeCol TIMESTAMP,
Value Float
) ENGINE = MergeTree()
ORDER BY id- Sample data for all these tables, use clickhouse-obfuscator if necessary