Comment by btilly

Comment by btilly 9 hours ago

3 replies

The biggest SQL antipattern is failing to recognize that SQL is actually a programming language.

Therefore you should create a consistent indentation style for SQL. See https://bentilly.blogspot.com/2011/02/sql-formatting-style.h... for mine. Second, you should try to group logical things together. This is why people should move subqueries into common table expressions. And finally, don't be afraid of commenting wisely.

xyzzy_plugh 8 hours ago

Style opinions are borderline irrelevant without appropriate linters.

  • javcasas 7 hours ago

    Go and use Google BigQuery auto-formatter in a complex query with CASE and EXTRACT YEAR FROM date, and you will have a totally different opinion.

    How that auto-formatter indents is borderly almost a hate crime. A thousand times better to indent manually.

    • OscarCunningham 7 hours ago

      I've even seen the BigQuery formatter change the behaviour of a query, by mixing a keyword from a comment into the real code.