由于 postgres `generate_series()`,Sqlfluff 规则 L025 中断

Sqlfluff rule L025 breaks due to postgres `generate_series()`

我正在使用 sqlfluff 来检查我的 postges 代码。在我的测试代码中,我遇到了一个 linting 错误,我不知道如何通过调整我的 sql 来解决,也不知道如何配置它。

我违反的规则是L025
问题是 sqlfluff 认为,我没有使用别名 i 因为我不写像 i.value.

这样的东西

使用以下代码:

insert into private.account (
  account_first_name,
  account_last_name,
  account_display_name,
  account_email,
  account_password
)
select
  'Random' as account_first_name,
  'User' as account_last_name,
  concat('Random User ', i) as account_display_name,
  concat('random', i, '@email.com') as account_email,
  gen_random_hash() as account_password
from generate_series(1, 200) as i;

和相应的错误:

== [test\generate_accounts.sql] FAIL
 L: 38 | P: 33 | L025 | Alias 'i' is never used in SELECT statement.
 All Finished!

我同意这里的 linter。 i 是 table 别名,不应用作列引用。使用起来更干净

from generate_series(1, 200) as g(i)

或您喜欢的任何命名。

然后将值引用为 g.i