sqlfluff / sqlfluff

A modular SQL linter and auto-formatter with support for multiple dialects and templated code.
https://www.sqlfluff.com
MIT License
7.35k stars 655 forks source link

Postgres: "insert into ... values ..." indentation problem #5855

Open nim8562 opened 1 month ago

nim8562 commented 1 month ago

Search before asking

What Happened

When I run sqlfluff-fix I get LT02-error and have my sql code changed from this. I use it via pre-commit hooks

INSERT INTO table (col1, col2, col3, col4)
    VALUES 
        (1, 2, 3, 4)
        (5, 6, 7, 8)

to this

INSERT INTO table (col1, col2, col3, col4)
VALUES 
(1, 2, 3, 4)
(5, 6, 7, 8)

Expected Behaviour

In documentation there is indentation for VALUES https://www.postgresql.org/docs/9.6/sql-insert.html I expected sqlfluff linter and fix not to fail on it or give opportunity to manage settings.

INSERT INTO table (col1, col2, col3, col4)
    VALUES 
    (1, 2, 3, 4)
    (5, 6, 7, 8)

or

INSERT INTO table (col1, col2, col3, col4)
    VALUES 
        (1, 2, 3, 4)
        (5, 6, 7, 8)

Observed Behaviour

L: 13 | P: 1 | LT02 | Line should not be indented. [layout.indent]

How to reproduce

Run sqlfluff lint or sqlfluff fix against this file

INSERT INTO table (col1, col2, col3, col4)
    VALUES 
        (1, 2, 3, 4)
        (5, 6, 7, 8)

Dialect

postgres

Version

sqlfluff, version 3.0.5

Configuration

[tool.sqlfluff.core] dialect = "postgres" exclude_rules = "L034" ignore = "templating" sql_file_exts = ".sql" max_line_length = 120

[tool.sqlfluff.indentation] indented_joins = false indented_using_on = true

[tool.sqlfluff.rules."layout.long_lines"] ignore_comment_clauses = true ignore_comment_lines = true

[tool.sqlfluff.rules."convention.count_rows"] prefer_count_1 = true

[tool.sqlfluff.rules."capitalisation.functions"] capitalisation_policy = "upper"

[tool.sqlfluff.rules."capitalisation.keywords"] capitalisation_policy = "upper"

[tool.sqlfluff.rules."capitalisation.literals"] capitalisation_policy = "upper"

[tool.sqlfluff.layout.type.column_constraint_segment] spacing_before = 'align' align_within = 'create_table_statement'

[tool.sqlfluff.layout.type.data_type] spacing_before = 'align' align_within = 'create_table_statement'

Are you willing to work on and submit a PR to address the issue?

Code of Conduct