0

How can I tell sqlfluff to do not add any character (in this case "_") after a number in an unquoted identifier?

For example, I want to lint a sql file with the following code:

SELECT
    CAST(FIELD_2PY AS decimal(28, 6) ) AS FIELD_2PY,
    CAST(FIELD_2PY_YTD AS decimal(28, 6) ) AS FIELD_2PY_YTD,
    CAST(FIELD_CY_L13P AS decimal(28, 6) ) AS FIELD_CY_L13P,
    CAST(FIELD_CY_L4WK AS decimal(28, 6) ) AS FIELD_CY_L4WK,
    CAST(FIELD_CY_L52WK AS decimal(28, 6) ) AS FIELD_CY_L52WK
FROM table1

After using sqlfluff (sqlfluff fix my-file.sql) with options:

[sqlfluff] 
dialect = snowflake 
templater = dbt 

sql_file_exts = .sql

# Some rules can be configured directly from the config common to other rules.       
[sqlfluff:rules] 
unquoted_identifiers_policy = all

[sqlfluff:rules:L014]  # Unquoted identifiers 
extended_capitalisation_policy = lower

I get the following linted code:

SELECT
    CAST(field_2_py AS decimal(28, 6) ) AS field_2_py,
    CAST(field_2_py_ytd AS decimal(28, 6) ) AS field_2_py_ytd,
    CAST(field_cy_l13_p AS decimal(28, 6) ) AS field_cy_l13_p,
    CAST(field_cy_l4_wk AS decimal(28, 6) ) AS field_cy_l4_wk,
    CAST(field_cy_l52_wk AS decimal(28, 6) ) AS field_cy_l52_wk
FROM table1

Which apply rule "L014 Inconsistent capitalisation of unquoted identifiers." and it change the capitalisation of the identifiers to lower case but it renames fields with a "_" after the numbers (i.e. FIELD_2PY is renamed to field_2_py)

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96

0 Answers0