SQLFluff is a SQL formatter that is implemented in Python. You can use this app to format one-off, adhoc sql that might not be worth saving to a file. Or you can use it to see what SQLFluff thinks of your queries. It's up to you!
You can check out the source code for this application on GitHub (click).
Paste your SQL and select your dialect. Hit that button and find your fixed SQL with the associated linter errors. Enjoy, friends 🌝.
SQLFluff is maintained by a group of
talented attractive and
selfless people who are all driven by a common disdain for poorly
formatted SQL. If you like fluff's treatment of your queries, feel
encouraged to check out our group on
This app runs on SQLFluff version 2.3.5, and applies all rules in that version. Here is a list of them:
|Implicit/explicit aliasing of table.
|Implicit/explicit aliasing of columns.
|Column expression without alias. Use explicit `AS` clause.
|Table aliases should be unique within each clause.
|Tables should not be aliased if that alias is not used.
|Enforce table alias lengths in from clauses and join conditions.
|Avoid table aliases in from clauses and join conditions.
|Column aliases should be unique within each clause.
|Ambiguous use of 'DISTINCT' in a 'SELECT' statement with 'GROUP BY'.
|'UNION [DISTINCT|ALL]' is preferred over just 'UNION'.
|Ambiguous ordering directions for columns in order by clause.
|Query produces an unknown number of result columns.
|Join clauses should be fully qualified.
|Inconsistent column references in 'GROUP BY/ORDER BY' clauses.
|Queries within set query produce different numbers of columns.
|Inconsistent capitalisation of keywords.
|Inconsistent capitalisation of unquoted identifiers.
|Inconsistent capitalisation of function names.
|Inconsistent capitalisation of boolean/null literal.
|Inconsistent capitalisation of datatypes.
|Use '!=' instead of '<>' for "not equal to" comparisons.
|Use 'COALESCE' instead of 'IFNULL' or 'NVL'.
|Trailing commas within select clause.
|Use consistent syntax to express "count number of rows".
|Comparisons with NULL should use "IS" or "IS NOT".
|Statements must end with a semi-colon.
|Top-level statements should not be wrapped in brackets.
|Use 'LEFT JOIN' instead of 'RIGHT JOIN'.
|Block a list of configurable words from being used.
|Consistent usage of preferred quotes for quoted literals.
|Enforce consistent type casting style.
|Jinja tags should have a single whitespace on either side.
|Operators should follow a standard for being before/after newlines.
|Leading/Trailing comma enforcement.
|Line is too long.
|Function name not immediately followed by parenthesis.
|'WITH' clause closing bracket should be on a new line.
|Blank line expected but not found after CTE closing bracket.
|Select targets should be on a new line unless there is only one select target.
|'SELECT' modifiers (e.g. 'DISTINCT') must be on the same line as 'SELECT'.
|Set operators should be surrounded by newlines.
|Files must end with a single trailing newline.
|Files must not begin with newlines or whitespace.
|References cannot reference objects not present in 'FROM' clause.
|References should be qualified if select has more than one referenced table/view.
|References should be consistent in statements with a single table.
|Keywords should not be used as identifiers.
|Do not use special characters in identifiers.
|Unnecessary quoted identifier.
|Do not specify 'else null' in a case when statement (redundant).
|Unnecessary 'CASE' statement.
|Query defines a CTE (common-table expression) but does not use it.
|Nested 'CASE' statement in 'ELSE' clause could be flattened.
|Join/From clauses should not contain subqueries. Use CTEs instead.
|Select wildcards then simple targets before calculations and aggregates.
|Prefer specifying join keys instead of using 'USING'.
|'DISTINCT' used with parentheses.
|Joins should list the table referenced earlier/later first.
|'SP_' prefix should not be used for user-defined stored procedures in T-SQL.