sql
SQL files: layout, capitalization, and references in the dialect of your database. Level all adds the join, cast, subquery, and LIMIT rules. Guide: SQL.
Selected when
Section titled “Selected when”A scope has file extensions .sql, .pgsql, or .psql. Also when postgres requires it.
Checks
Section titled “Checks”sqlfluff
Section titled “sqlfluff”Lints every SQL file for layout, capitalization, aliasing, and ambiguous references, in the dialect that sql.dialect names.
Runs at the commit stage. gspot check --fix fixes what it can.
When every SQL file follows one style, a reviewer can focus on what each statement does.
What to do
Section titled “What to do”Run the fix: command that the report prints for the rules that fix themselves, then fix each line that SQLFluff still names.
Example
Section titled “Example”The query select id from user_accounts; reports CP01 for lowercase keywords. Write it as SELECT id FROM user_accounts;.
Turn it off
Section titled “Turn it off”gspot ignore sql/sqlfluff --paths "<path>" --reason "<why>"gspot ignore sql/sqlfluff --rule <rule> --reason "<why>"To silence one place, write a comment such as:
SELECT * FROM orders -- noqa: AM04 -- reason: the view mirrors every columnkeywords
Section titled “keywords”Checks, in the Postgres dialects, the keywords that SQLFluff does not read: the keywords and built-in types of PL/pgSQL, ANY, ALL, SOME, EXISTS, NOT, DISTINCT, and ARRAY before a bracket with their space, and the case of NEW, OLD, and the other PL/pgSQL names.
Runs at the commit stage.
SQLFluff reads a function body as a string and some keywords as function calls, so its capitalization rules pass them in any case.
What to do
Section titled “What to do”Run gspot check --fix --only sql/keywords, which writes the keywords and types in upper case, the space before each bracket, and each PL/pgSQL name in one case.
Example
Section titled “Example”if v_id is null then in a function body reports keyword-case on if and then. Run gspot check --fix to write them in upper case.
Lint rules
Section titled “Lint rules”| Rule | What it checks | What to do |
|---|---|---|
keyword-case |
A keyword that SQLFluff does not read as one stands in upper case: ANY, ALL, SOME, EXISTS, NOT, DISTINCT, and ARRAY before a bracket, and the keywords of PL/pgSQL in a function body, such as BEGIN, IF, INTO, PERFORM, and RETURN. |
Run gspot check --fix, which writes the keyword in upper case. |
keyword-bracket |
One space stands between ANY, ALL, SOME, EXISTS, NOT, or DISTINCT and the bracket after it, and none between ARRAY and its bracket. |
Run gspot check --fix, which writes the space. |
special-name |
A PL/pgSQL name, NEW, OLD, FOUND, SQLERRM, SQLSTATE, or a TG_ name, stands in upper case or in lower case. |
Run gspot check --fix, which writes the name in upper case. |
type-case |
A built-in type in the declarations of a PL/pgSQL body stands in upper case. | Run gspot check --fix, which writes the type in upper case. |
Turn it off
Section titled “Turn it off”gspot ignore sql/keywords --paths "<path>" --reason "<why>"gspot ignore sql/keywords --rule keyword-case --reason "<why>"Settings
Section titled “Settings”| Setting | What it sets |
|---|---|
limits.max_file_lines |
The most lines one file may have, not counting blank lines and comment-only lines. |
sql.dialect |
The SQL dialect that SQLFluff parses, such as postgres. The postgres configuration sets it. A [[scope]] sets another dialect for its folder. |
Rules for coding agents
Section titled “Rules for coding agents”| Rule file | Installed when |
|---|---|
.gspot/rules/SQL.md |
Always |
Tools and versions
Section titled “Tools and versions”| Tool | Version |
|---|---|
| sqlfluff | 4.4.0 |
Files gspot writes
Section titled “Files gspot writes”.gspot/configurations/sql/sqlfluff.cfg