Warn if "ORDER BY" is used on multiple columns and only *some* columns specify explicit ordering
See original GitHub issueWe had a bad bug recently in a project where somebody wrote this:
ORDER BY a, b DESC
They thought it meant this:
ORDER BY a DESC, b DESC
But it actually means this:
ORDER BY a ASC, b DESC
Suggestion: SQLFluff should warn that it’s “potentially ambiguous” if an ORDER BY
specifies the order direction ASC
or DESC
on some but not all columns. An automatic fix for this would be to have SQLFluff add ASC
to any columns that didn’t specify a sort order in the ORDER BY
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
SQL multiple column ordering - Stack Overflow
If you want to select records from a table but would like to see them sorted according to two columns, you can do...
Read more >SQL Server ORDER BY performance tips
In this article, we will explore how the ORDER BY statement affects the query performance and we will also learn some performance tips ......
Read more >SQLite Simple Folks: ORDER and LIMIT
Breaking a "tie" in a sort is as easy as specifying a second column to ORDER BY : use a comma to specify...
Read more >SQL Server ORDER BY clause By Practical Examples
This tutorial shows you how to use the SQL Server ORDER BY clause to sort the result set of a query by a...
Read more >Creating ORDER BY clauses for multiple-column sorts in ... - IBM
The ORDER BY clause specifies the order of the rows of a results table for an SQL statement.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello! I’d like to try to take a stab at this. I really like sqlfluff. Niall said this would be a good first issue for me. I am hoping to carve out time this weekend to start on it if that’s okay.
@bdelamotte: Thank you so much for the code! This was the first time I’d worked on a lint rule that made fixes to the code, and your code got me 80% of the way to finished. 💯