Skip to content

[jdbc-v2] UNION DISTINCT fails to parse #2500

@troyjcurt

Description

@troyjcurt

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

  1. make a prepared statement using the above query
  2. 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 TABLE statements 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions