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.

Rule Suggestion: disallow expression on same line as SELECT (if num_expressions>1)

See original GitHub issue

Given this example:

SELECT Md5(-1)            AS gl_account_key,
       0                  AS gl_account_number,
       'Unknown'          AS gl_account_name,
       'Unknown'          AS gl_major_category,
       'Unknown'          AS reporting_major_category

SQLFluff fixes as:

SELECT Md5(-1)            AS gl_account_key,
    0                  AS gl_account_number,
    'Unknown'          AS gl_account_name,
    'Unknown'          AS gl_major_category,
    'Unknown'          AS reporting_major_category

Whereas I think the best practice should be:

SELECT 
    Md5(-1)            AS gl_account_key,
    0                  AS gl_account_number,
    'Unknown'          AS gl_account_name,
    'Unknown'          AS gl_major_category,
    'Unknown'          AS reporting_major_category

In other words: If the number of expressions is greater than one, none of them should share a line with SELECT and all should be indented the standard 4 characters.

Thoughts? Agree/disagree?

I qualify based on the number of expressions because a case can be made that this:

SELECT
    mycol
FROM mytable

…is less desirable/readable than:

SELECT mycol
FROM mytable

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aaronsteerscommented, Oct 6, 2020

@pwildenhain - Indeed. Thank you for linking the two. Where the two differ, as far as I can tell, is just the comment from Alan on #352 related to multiple first line columns being okay, whereas here I’ve suggested only allowing when a single expression is named.

Taking the safe assumption that line length is already enforced, I think I’m okay with all of these:

select col_a, col_b from my_table
select col_a, col_b
from my_table
select col_a
from my_table

Whereas these would be anti-patterns:

select col_a,
    col_b
from my_table
select col_a, col_b
    col_c
from my_table
1reaction
alanmcruickshankcommented, Aug 30, 2020

I’m open to this as a rule, with a few potential exceptions.

  • If there is only a single column in the select, then the rule does not apply (as per your last example), this would be similar to the logic of L013, which allows SELECT 1 FROM blah without an alias for the column.
  • Your first example actually has a hanging indent, and I think these should still be allowed, although perhaps this should be configurable for this rule. I’ll add some examples below.
  • The configuration from how much to indent by default should come from the master config and respect the overall settings for tabs/spaces etc…

e.g.

GOOD (Scalar query)

SELECT 1
FROM foo

(Hanging indent, i.e. a & c have the same indent. There’s some logic in L003 to work this out that should probably be more generic.)

SELECT a, b,
       c, d
FROM bar

BAD

SELECT a,
    b
FROM foobar

… should fix to …

SELECT
    a,
    b
FROM foobar
Read more comments on GitHub >

github_iconTop Results From Across the Web

Select form and its label in same line in bootstrap3
Here is one way : Bootply : http://www.bootply.com/YzaMGyRq99. CSS : select.form-control{display:inline-block}. HTML :
Read more >
How To Prevent Line Breaks Using CSS - DigitalOcean
Text wrapping can also prevent horizontal scrolling. But there are times when you want blocks of text to stay on the same line,...
Read more >
CSS text-align-last property - W3Schools
Notice that the text-align-last property sets the alignment for all last lines within the selected element. So, if you have a <div> with...
Read more >
How to Prevent Two or More Words from Being Split into ...
How to selectively disable word wrapping on a web page so that two or more words are not split and placed on separate...
Read more >
user-select - CSS: Cascading Style Sheets - MDN Web Docs
If a double-click or context-click occurred in sub-elements, the highest ancestor with this value will be selected. contain. Enables selection ...
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