Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clickhouse): ensure that ALL and DISTINCT are rendered for except and intersect #4007

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

cpcloud
Copy link
Contributor

@cpcloud cpcloud commented Aug 29, 2024

Closes #4005.

Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@georgesittas georgesittas merged commit cb172db into tobymao:main Aug 29, 2024
6 checks passed
@cpcloud cpcloud deleted the clickhouse-set-op branch August 29, 2024 14:13
@georgesittas
Copy link
Collaborator

@cpcloud I think there's actually an issue here:

>>> import sqlglot
>>> sqlglot.parse_one("""
... SELECT * FROM CTE1
... EXCEPT
... SELECT * FROM CTE2
... """, "clickhouse").sql("clickhouse")
'SELECT * FROM CTE1 EXCEPT DISTINCT SELECT * FROM CTE2'

EXCEPT without DISTINCT is, as I think you mentioned, EXCEPT ALL:

WITH CTE1 AS (
    SELECT 1 AS id, 'Alice' AS name
    UNION ALL
    SELECT 2 AS id, 'Bob' AS name
    UNION ALL
    SELECT 3 AS id, 'Charlie' AS name
    UNION ALL
    SELECT 4 AS id, 'Diana' AS name
    UNION ALL
    SELECT 5 AS id, 'Eve' AS name
    UNION ALL
    SELECT 1 AS id, 'Alice' AS name
),
CTE2 AS (
    SELECT 3 AS id, 'Charlie' AS name
    UNION ALL
    SELECT 4 AS id, 'Diana' AS name
    UNION ALL
    SELECT 6 AS id, 'Frank' AS name
)

-- Produces [(1, 'Alice'), (2, 'Bob'), (1, 'Alice'), (5, 'Eve')]
SELECT * FROM CTE1
EXCEPT
SELECT * FROM CTE2;

@georgesittas
Copy link
Collaborator

Fixed in #4009

gforsyth pushed a commit to ibis-project/ibis that referenced this pull request Aug 30, 2024
…lglot; add tpcds query 87 (#9959)

Add query 87 and workaround a bug in sqlglot (fixed upstream in
tobymao/sqlglot#4007)
hellozepp pushed a commit to hellozepp/sqlglot-doris that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing DISTINCT in EXCEPT statement when producing ClickHouse SQL
2 participants