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

DISTINCT ON query with ORDER BY expression with non-default NULLS FIRST/LAST errors out #107848

Closed
msirek opened this issue Jul 29, 2023 · 1 comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@msirek
Copy link
Contributor

msirek commented Jul 29, 2023

Describe the problem
The following errors out on CRDB, but succeeds in postgres:

CREATE TABLE t1 (id int, str text);
CREATE TABLE t2 (id int, num int);
SELECT
DISTINCT ON (COALESCE(t2.id, t1.id))
t1.id,
t1.str
FROM t1 JOIN t2 ON t1.id = t2.id
ORDER BY COALESCE(t2.id, t1.id) DESC NULLS FIRST;

error (42P10): SELECT DISTINCT ON expressions must match initial ORDER BY expressions

#107842 Fixes the ORDER BY column case. This issue is opened to handle all other cases where we order by an expression.

Environment:

  • CockroachDB version: All versions, v23.1 and prior

Jira issue: CRDB-30214

@msirek msirek added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Jul 29, 2023
@github-project-automation github-project-automation bot moved this to Triage in SQL Queries Jul 29, 2023
@mgartner mgartner moved this from Triage to New Backlog in SQL Queries Aug 3, 2023
@exalate-issue-sync exalate-issue-sync bot added the T-sql-queries SQL Queries Team label Aug 8, 2023
@exalate-issue-sync exalate-issue-sync bot removed the T-sql-queries SQL Queries Team label Aug 9, 2023
@rafiss rafiss added the T-sql-queries SQL Queries Team label Nov 24, 2023
@yuzefovich
Copy link
Member

Closing as a dup of #107516

@github-project-automation github-project-automation bot moved this from Backlog to Done in SQL Queries Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Archived in project
Development

No branches or pull requests

3 participants