question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warn if "ORDER BY" is used on multiple columns and only *some* columns specify explicit ordering

See original GitHub issue

We 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:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
bdelamottecommented, Nov 17, 2020

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.

0reactions
barrywhartcommented, Apr 30, 2021

@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. 💯

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found