Live data from Hacker News

Sqlfluff the SQL Linter for Humans

sqlfluff.com

11–20 of 95 posts

Re: Sqlfluff the SQL Linter for Humans

#11
There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first.

Eg. some people like to align the clauses vertically and use a leading, not trailing, comma.

    select a
         , b
         , count(*) as count
      from table
     where cond1
       and cond2
     group by a, b
     order by count desc

Re: Sqlfluff the SQL Linter for Humans

#12
post #5

This is a nice idea, but my problem with most of these tools is that they work with pure SQL/JS/whatever files, which isn't always the case. For example, if you use something like myBatis, you'll probably build the SQL dynamically, which could be stored in a mapper XML file: https://mybatis.org/mybatis-3/dynamic-sql.html Not only that, but certain frameworks have you embedding SQL inside of the main application code,…

I haven't used sqlfluff, but they support jinja templating and in those cases they ignore spacing problems. So maybe your use case can be supported?

Re: Sqlfluff the SQL Linter for Humans

#14
post #5

This is a nice idea, but my problem with most of these tools is that they work with pure SQL/JS/whatever files, which isn't always the case. For example, if you use something like myBatis, you'll probably build the SQL dynamically, which could be stored in a mapper XML file: https://mybatis.org/mybatis-3/dynamic-sql.html Not only that, but certain frameworks have you embedding SQL inside of the main application code,…

Yeah, you need to read more of the sqlfluff documentation. :-)

Re: Sqlfluff the SQL Linter for Humans

#15
post #11

There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc

Leading comma is configurable, but I wouldn't know if the linter allows for that layout. Can't say I've seen it before, is it specific to a particular development environment?

Re: Sqlfluff the SQL Linter for Humans

#17
Sorry - didn't get a chance to go through the documentation much yet... A problem we are looking to catch early in the development process is for things we don't want folks to do, even if they are technically correct. For example, dropping a column or altering the datatype/nullability in such a way that the table goes into reorg pending. I know we can write our own regex to look for that specific syntax, but I've not yet found a tool with those kinds of rules either build out already, or easy to add/maintain.

Re: Sqlfluff the SQL Linter for Humans

#18
post #16

I wondered how much good you could do with an SQL linter that didn't have any access to the underlying schema, and the answer seems to be "mostly whitespace and capitalization issues".

Makes you wonder if this tool would be better a code formatter rather than linter?

Re: Sqlfluff the SQL Linter for Humans

#19
post #11

There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc

Leading comma is configurable, but I wouldn't know if the linter allows for that layout. Can't say I've seen it before, is it specific to a particular development environment?

It’s an informal way some people write SQL if they’re developing a script.

I’ve done it this way before because it was quicker to edit, and and remove lines. But it’s not a format I’d particularly like to share with others because it looks weird.

Re: Sqlfluff the SQL Linter for Humans

#20
post #4

This is a linter which complains about spaces and newlines, but lets "WHERE col = NULL" pass (which can never be meaningful) just fine? Obviously this depends on the rules configuration, but just judging that first smell test, it seems very ill thought out.

I guess it depends on what you want out of a linter e.g. if you want it to check just syntax or semantics as well. Is “= NULL” syntactically correct?

The compiler checks syntax - if that’s all a linter did it wouldn’t be very useful.
Post reply on HN