如何避免 sqlfluff 将字符添加到未加引号的标识符,同时仍然对文件进行 linting?
如何告诉 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论