Live data from Hacker News

Sqlfluff the SQL Linter for Humans

sqlfluff.com

91–95 of 95 posts

Re: Sqlfluff the SQL Linter for Humans

#91
post #86

Earlier quoted context omitted.

This looks nearly the same, but it's much easier to write and generates less spurious diffs: select a , b , count(*) as count from table join table2 on table.key1 = table2.key1 and table.key2 = table2.key2 and DATEADD('day, 1, table.key3) = table2.key3 where cond1 and cond2 group by a, b order by count desc The largest difference is that the equal operators aren't aligned anymore, but on my opinion, aligning them is…

Nice changes, I like it! I will say I really like aligning the join clauses, but I'll try writing things this way for a little while and see if it sticks.

The only thing I require from an SQL formatter is to make typos and boolean mistakes super easy to spot, especially as it grows in size. At first glance it might seem strange, but I like indentation on even the first term of an AND.

    SELECT
        a,
        b,
        count(*) as count
    FROM
        table
    JOIN
        table2
    ON
            table.key1 = table2.key1
        AND
            table.key2 = table2.key2
        AND
            -- 1 day apart
            DATEADD('day', 1, table.key3) = table2.key3
    WHERE
            cond1
        AND
            cond2
        AND
            (
                cond3
            OR
                cond4
            )
    GROUP BY
        (a, b)
    ORDER BY
        count desc,
        a asc
    LIMIT
        1000
    ;
Yes, that's a lot of whitespace, but it helps for complex queries.

Re: Sqlfluff the SQL Linter for Humans

#93
post #91
post #86

Earlier quoted context omitted.

Nice changes, I like it! I will say I really like aligning the join clauses, but I'll try writing things this way for a little while and see if it sticks.

The only thing I require from an SQL formatter is to make typos and boolean mistakes super easy to spot, especially as it grows in size. At first glance it might seem strange, but I like indentation on even the first term of an AND. SELECT a, b, count(*) as count FROM table JOIN table2 ON table.key1 = table2.key1 AND table.key2 = table2.key2 AND -- 1 day apart DATEADD('day', 1, table.key3) = table2.key3 WHERE cond1 A…

Well, there's an inherent conflict between making individual queries easier to read and making your entire code easier to read.

How much whitespace you need is completely dependent on what exactly you are writing.

Re: Sqlfluff the SQL Linter for Humans

#94
post #38
post #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…

It's pretty new functionality in sqlfluff, but it now supports user defined plugins for org-specific rules if you want to forbid something more obscure. Documentation is sketchy, but you can see the proof of concept here: https://github.com/sqlfluff/sqlfluff/tree/main/plugins/sqlfl...

Thanks, I'll take a closer look there...

Re: Sqlfluff the SQL Linter for Humans

#95

After relying on Prettier for a while, it feels very strange to me to have a linter that complains over minor formatting differences instead of just a tool that automatically fixes them.

It does both. Linting and fixing are done at different times.
Post reply on HN