Live data from Hacker News

Sqlfmt: an opinionated online SQL formatter

cockroachlabs.com

1–10 of 94 posts

Re: Sqlfmt: an opinionated online SQL formatter

#3
Great idea.

I work on a project that's grown in complexity and team size. Developers have come and gone. Sometimes a bit of code that's grown over a few years needs its style to evolve. This kind of formatter clearly realizes this.

What I tell developers that complain about this or that style is that it's more important to have a consistent code style throughout the lifetime of a project, then to adopt whatever bracing style someone happens to like at the time.

I'd really like all of my code to be automatically formatted with a tool like this, as part of the build process. This would help with situations where code evolves, as it would reformat it when needed.

Re: Sqlfmt: an opinionated online SQL formatter

#5
post #2

I'm sad this isn't available as a binary, it's not much use to me as a website.

It's available as part of the cockroach binary (https://www.cockroachlabs.com/docs/releases/v2.1.0-beta.2018...) as a subcommand. And an external contributor has made a more standalone version at https://github.com/lopezator/sqlfmt.

Re: Sqlfmt: an opinionated online SQL formatter

#6

that would be really cool to have as a local package you can plug into your text editor instead of copy and paste. people using this at companies might leak sensitive information or possible attack vectors to the opaque service.

See my other comment. There are a few options for a local binary.

Re: Sqlfmt: an opinionated online SQL formatter

#8
post #2

I'm sad this isn't available as a binary, it's not much use to me as a website.

I searched around and found https://github.com/jackc/sqlfmt, which is an older open source project also called sqlfmt, also written in Go. I don't know anything about how they compare.

Re: Sqlfmt: an opinionated online SQL formatter

#9
If you're working with something close to PostgreSQL syntax support, why wouldn't you start with pgFormatter (http://sqlformat.darold.net/)? It's been around for awhile and I can't see anything new or substantially more advanced in the proposed solution.

I have to say, I do most of my development work in the database, and I'm not thrilled with any of the automatic formatters thus far. The ones I've seen can do a good job in many cases, but if you start getting very advanced at all, the weaknesses of an automatic formatting approach start to become more evident. It may just be that anything other than relatively simple SQL, PL/SQL are not well suited for automatic formatting.

I'm still working through a good set of formatting rules, and I always find I end up making exceptions for readability.

Post reply on HN