sqlparameter-passinglintersqlfluff

sqlfluff with named parameters


I'm investigating linting SQL files in a project. sqlfluff seems good and I'm keen to get it integrated into the pre-commit checks for the project I'm working on.

However, the linter is currently producing false positives for any parameter use in parameterised SQL.

I'm using named-style parameters:

WHERE name=:name

https://www.python.org/dev/peps/pep-0249/#paramstyle

Despite several searches, I couldn't find anything on getting sqlfluff to work well with named-style parameters. I've tried changing the parameter style but my DB driver didn't like it.

Is anyone using sqlfluff with named parameters? Could you point me in the direction of the relevant documentation or post a solution?


Solution

  • Upgrading to the latest version of sqlfluff and using the postgres dialect resolves these false positive errros.

    To update sqlfluff:

    python3 -m pip install --upgrade sqlfluff
    

    To select the postgres dialect:

    sqlfluff lint --dialect postgres database_query.sql
    

    This should accept named parameters without complaining.

    The default dialect (at the point of writing) is ansi