Live data from Hacker News

Sqlfmt: an opinionated online SQL formatter

cockroachlabs.com

61–70 of 94 posts

Re: Sqlfmt: an opinionated online SQL formatter

#61

This looks great! I notice you mentioned Prettier in the post — do you have any plans to integrate sqlfmt with that? Prettier actually has a beta Postgres plugin, but progress on it seems to have stalled. Hooking it up with sqlfmt would be neat - then prettier could format SQL inside other languages too, like code fences in Markdown or template literals in JS.

I wish they didn't stop development: https://github.com/benjie/prettier-plugin-pg

I use plv8 very often, and this would be perfect.

Re: Sqlfmt: an opinionated online SQL formatter

#62

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 understood why people want to uppercase anything. It's like source code from 1970, when even bold highlight was something unavailable and developers used uppercase for keywords. I don't uppercase SQL, I prefer software which does proper highlighting.

In the beginning, there was uppercase

Re: Sqlfmt: an opinionated online SQL formatter

#63
post #43

Earlier quoted context omitted.

The formatter adheres to CockroachDB rules which is why it acts like you describe. Case is insensitive in names unless you double quote it. Postgres-style (CockroachDB is one) uses "$1" for placeholders instead of "?". Adding "?" would complicate our grammar enough that it's not worth adding it. sqlfmt is not super useful for non-postgres grammars.

Consider those of us stuck with Java adapters to Postgres, which means Postgres syntax but ? for placeholders.

Is that a thing? The Java driver must actually parse those and convert them. Java is crazy. https://github.com/mjibson/sqlfmt/issues/25 is the issue to track '?' as placeholders.

Re: Sqlfmt: an opinionated online SQL formatter

#64

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?

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?

Re: Sqlfmt: an opinionated online SQL formatter

#65

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?

If I've got my developer hat on, yeah, sort of. I still find the case differences more pronounced without necessarily forcing me into a more in-my-face code formatting theme. Also, for all the reason A code format is important, the fact that I have 20 years experience with up-to-now SQL norms mean that I'm trained to look for certain things and can, almost without thinking, focus in on those with the help of historical formatting. Arbitrary changes to that history mean that now I have to discard that muscle memory and learn new ways of looking at things... I'm not sure the gain of a few less caps locks keystrokes merits forcing that learning curve. Sure the kids won't care about that because there's nothing to lose, but some of us old timers lose the benefit of our experience.

But developers with good tooling to deal with more static views of the code aren't the only readers of SQL, and perhaps not the most common.

With my DBA hat on, trying to figure out what's going on reading through logs and such, I don't always have that kind of tooling available. In this context the casing can help as well.... and this may form some of my bias; my first professional experiences on the application side of the world were in very much DBA roles dealing with other people's applications running on my servers. Insofar as access tools preserve developer formatting, having good "color-blind" formats made reading complex queries easier.

Re: Sqlfmt: an opinionated online SQL formatter

#66
post #55

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?

Dimitri Fontaine writes about this in Master PostgreSQL in Application Development. He agrees. I found this to be a great modern sql resource.

If you namedrop something always link https://tapoueh.org/

Re: Sqlfmt: an opinionated online SQL formatter

#67
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.

I thought it was a ploy to get people to install cockroach, that's what I'm doing now.

Re: Sqlfmt: an opinionated online SQL formatter

#68

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 understood why people want to uppercase anything. It's like source code from 1970, when even bold highlight was something unavailable and developers used uppercase for keywords. I don't uppercase SQL, I prefer software which does proper highlighting.

When I see non uppercased SQL I think I’m reading it from some hipster that just discovered e e cummings and that makes me angry. Added to the fact that I’m writing SQL so I’m already angry (thanks poster above! I’m stealing that).

But seriously upper case helps my eyes focus on the sql commands so that I have some sort of hand hold on the wall of text.

Re: Sqlfmt: an opinionated online SQL formatter

#69

Earlier quoted context omitted.

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

If I've got my developer hat on, yeah, sort of. I still find the case differences more pronounced without necessarily forcing me into a more in-my-face code formatting theme. Also, for all the reason A code format is important, the fact that I have 20 years experience with up-to-now SQL norms mean that I'm trained to look for certain things and can, almost without thinking, focus in on those with the help of historic…

Yeah indeed -- though I'd prefer to write all lowercase for the sake of ease, I too stick to the 'uppercasing' norms mainly to help with ease of readability -- especially in shell-only environments where syntax highlighting isn't available [e.g., using psql]
Post reply on HN