Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I’m using sqlfluff to lint my postges code. I’m down to a single linting error, in my test code, that I dont know how to fix by adjusting my sql nor how to configure it.

The rules im breaking is L025.
The issue is that sqlfluff thinks, i’m not using the alias i because I dont write womething like i.value.

With the following code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;

and the coresponding error:

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

>Solution :

I do agree with the linter here. i is a table alias and shouldn’t be used as a column reference. It’s cleaner to use

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

or whatever naming you prefer.

Then reference the value as g.i

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading