Live data from Hacker News

Sqlfmt: an opinionated online SQL formatter

cockroachlabs.com

81–90 of 94 posts

Re: Sqlfmt: an opinionated online SQL formatter

#81

Tangentially related. I'm of the opinion that SQL shouldn't be uppercased. I don't want to hit shift or caps lock and I find lowercase easier to read. Are there others out there like me? I assume I'm in the minority, but I don't understand why. People stopped uppercasing HTML tags, why can't we do the same with SQL?

I'm all for uppercasing the keywords and lowercasing your variables and columns. It makes for much easier reading...

Re: Sqlfmt: an opinionated online SQL formatter

#82

Tangentially related. I'm of the opinion that SQL shouldn't be uppercased. I don't want to hit shift or caps lock and I find lowercase easier to read. Are there others out there like me? I assume I'm in the minority, but I don't understand why. People stopped uppercasing HTML tags, why can't we do the same with SQL?

I always uppercase the keywords. Maybe for short one-off queries I’ll type all lowercase. But for compound statements, readability is more important, and keywords usually are a small portion of the overall query code anyway

Re: Sqlfmt: an opinionated online SQL formatter

#83
post #50

Looks really cool, but I have one suggestion. Have you considered using leading commas? It makes big SQL statements much easier to edit and it improves diffs. I normally use trailing commas for my code, but most sql dialects don't support it so I fallback to leading ones there.

Oh god, no. No leading commas, anywhere. Not in javascript, not in SQL. It's like nails on a chalkboard. Funny because I was reading other people's comments and thinking "wow, that person is VERY opinionated on query formatting" (but now here I am).

> Funny because I was reading other people's comments and thinking "wow, that person is VERY opinionated on query formatting" (but now here I am).

There are opinions, and there are crimes against humanity (although that is a matter of opinion).

Re: Sqlfmt: an opinionated online SQL formatter

#85

Earlier quoted context omitted.

First, I'm sure mere inertia plays a role, but there are practical reasons as well if you're writing more than trivial SQL queries. In most other languages you can read the statements fairly linearly, one statement leads to the next, and to the next, etc. At least within functions/methods and then you usually have indentation to help with understanding boundaries. Each "logical line" may be spread out over one or eve…

Wouldn't syntax highlighting help with most of the issues you've outlined?

Syntax highlighting is a huge boon working with SQL, but unfortunately you often find you are working with SQL embedded as a string in some other programming language.

I wonder if programming languages should have a way of specifying that a string constant contains embedded code or a template, so text editors can display it accordingly.

I deal with a lot of SQL embedded in code, and prefer uppercase keywords as it seems to help me visually parse the overall file.

Re: Sqlfmt: an opinionated online SQL formatter

#86
post #85

Earlier quoted context omitted.

Wouldn't syntax highlighting help with most of the issues you've outlined?

Syntax highlighting is a huge boon working with SQL, but unfortunately you often find you are working with SQL embedded as a string in some other programming language. I wonder if programming languages should have a way of specifying that a string constant contains embedded code or a template, so text editors can display it accordingly. I deal with a lot of SQL embedded in code, and prefer uppercase keywords as it se…

PyCharm (and likely other editors by Jetbrains) supports embedded programming languages! However, language level support so that this could be automatically done by all editors would be great.

Re: Sqlfmt: an opinionated online SQL formatter

#87

Tangentially related. I'm of the opinion that SQL shouldn't be uppercased. I don't want to hit shift or caps lock and I find lowercase easier to read. Are there others out there like me? I assume I'm in the minority, but I don't understand why. People stopped uppercasing HTML tags, why can't we do the same with SQL?

I never uppercase the SQL keywords. If it's more than a one-liner select statement, I format it so the indentation tells me what's going on. To throw out a tossed-off example: select P.full_name, A.full_address, AT.type as address_type_name from People as P inner join Addresses as A on P.address_id=A.id where P.deleted is null

That's also my preferred approach. When formatting your code like this, the caps don't really offer an advantage anymore.

Plus, it's more comfortable to type as well.

Re: Sqlfmt: an opinionated online SQL formatter

#88
post #85

Earlier quoted context omitted.

Wouldn't syntax highlighting help with most of the issues you've outlined?

Syntax highlighting is a huge boon working with SQL, but unfortunately you often find you are working with SQL embedded as a string in some other programming language. I wonder if programming languages should have a way of specifying that a string constant contains embedded code or a template, so text editors can display it accordingly. I deal with a lot of SQL embedded in code, and prefer uppercase keywords as it se…

a lot of programming languages do have a way of specifying that a string constant contains embedded code or a template. Sublime Text for example will look for PHP heredocs with an identifier of XML, HTML, SQL etc. to know what to lex/highlight the string as. Or it will check whether the string starts with an uppercase "SELECT", as the chances are it's gonna be SQL. Code fences in GitHub Formatted Markdown are also a good example of this hinting.

Re: Sqlfmt: an opinionated online SQL formatter

#89
post #28
post #19

Brief question, only tangentially related: Is it me or is "opinionated" software popping up all over the place? It looks to me like the author considers it a selling point, too. Can someone explain to me why I would want an "opinionated" software over any regular old software? Especially over a configurable software? I'm not a native speaker, but I never encountered "opinionated" being used with positive connotation.…

The word does indeed have initially negative connotations. Perhaps it resonates more positively now to people who have had to work with "flexible" software such as Spring in the old days. There were 100 ways to skin a cat with old Spring, and each way was a tortuous devil's brew of XML. Googling for any solution was a nightmare, exacerbated by hundreds of wannabe experts polluting the interwebs with their own strange…

That's a good point.

In programming, there's the idea that "The code shouldn't merely work, it should clearly work". If your configuration system becomes so complex that the same principle applies there, that's a bad sign.

Re: Sqlfmt: an opinionated online SQL formatter

#90
post #17

Author here. Based on feedback I am going to make a sqlfmt binary for easy editor integration. You can currently already do this by using the CockroachDB binary ( https://www.cockroachlabs.com/docs/releases/v2.1.0-beta.2018... ) but understandably people want a more minimal solution.

Hey! I love your tool.

Any chance of allowing keywords that are specific to a SQL implementation? (e.g. PostgreSQL)

If I enter "CREATE MATERIALIZED VIEW ... WITH DATA;" in for example, it would tell me "materialized" and "with data" is wrong.

Post reply on HN