如何避免 sqlfluff 将字符添加到未加引号的标识符,同时仍然对文件进行 linting?

发布于 2025-01-09 08:28:47 字数 1328 浏览 0 评论 0原文

如何告诉 sqlfluff 不要在不带引号的标识符中的数字后面添加任何字符(在本例中为“_”)?

例如,我想使用以下代码对 sql 文件进行 lint:

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

使用带有选项的 sqlfluff (sqlfluff fix my-file.sql) 后:

[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

我得到以下 lint 代码:

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

哪个应用规则“L014 不一致”未加引号的标识符的大写。”它将标识符的大写更改为小写,但在数字后用“_”重命名字段(即 FIELD_2PY 重命名为 field_2_py

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文