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 #2656: correctly transform DISTINCT with ORDER BY into DISTINCT ON #2662

Merged
merged 1 commit into from
Nov 24, 2021

Conversation

Mytherin
Copy link
Collaborator

Fixes #2656. We choose to mimick SQLite's behavior here and transform the query into a DISTINCT ON with the queries that are mentioned in the SELECT clause, i.e. the following two queries are identical:

CREATE TABLE T (t1 int, t2 int);
INSERT INTO t VALUES (1, 1), (1, 2);

SELECT DISTINCT t1
FROM T
ORDER BY t1, t2;

SELECT t1 FROM (
  SELECT DISTINCT ON(t1) t1, t2
  FROM T
  ORDER BY t1, t2
) T;

@Mytherin Mytherin merged commit 5e06605 into duckdb:master Nov 24, 2021
@Mytherin Mytherin deleted the issue2656 branch December 3, 2021 14:25
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.

DISTINCT + ORDER produces incorrect result
1 participant