SPBS
8 months ago
> Spaces should be used to line up the code so that the root keywords all end on the same character boundary.
SELECT file_hash
FROM file_system
WHERE file_name = '.vimrc';
This style is annoying and I wish it gained less traction. It looks neat but it puts so much burden on the query writer, especially when you modify the query and all of the sudden you need to indent multiple lines just to make them all align. You know what's neat and still easy to modify/diff? Just indent a new line for each row. SELECT
file_hash
FROM
file_system
WHERE
file_name = '.vimrc';
abraae
8 months ago
IMO in the modern day there is no place for any indentation styling that can't be achieved automatically via a pretty printer such as golang has.
snorremd
8 months ago
This. Relying on developers manually trying to follow a style guide is a recipe for not having a consistent style. Instead something like pgFormatter should be used. I'm not sure what the state of SQL formatters and IDE support is these days. Not sure how many command based options there are.
And people who use things like Datagrip or other IDEs will probably format with their IDE's preferences unless there is a plugin for things like pgFormatter. This works well if there is a company mandated editor/IDE, but not so well when you have developers across various editors and IDEs.
kmoser
8 months ago
Automatic formatters and pretty printers never seem to be able to make the exceptions necessary for me to use them. For example, I want the contents of all my HTML tags to be formatted as one long line (think of <p> tags), except when they happen to contain a SQL statement which I want to remain formatted exactly as written.
emmelaich
8 months ago
Also, could uppercase go away and never come back? Please?
y42
8 months ago
but why? it's a quick and easy way to distinguish commands from arguments
dagss
8 months ago
Why do you not make that argument for "if" and "else" in Go/Java/...?
Editors highlight syntax.
thiht
8 months ago
Editors don’t syntax highlight SQL queries written as strings. That’s the main reason I write my queries with uppercase keywords in my Go programs
wcrossbow
8 months ago
Editors can highlight SQL queries embedded as strings. Neovim can do it, and I'm pretty confident it's not going to be alone in that respect.
edit: Not the editor I use but thought it might be helpful. Here is an extension, which I haven't tested, to do this in VSCode: https://marketplace.visualstudio.com/items?itemName=iuyoy.hi...
mijamo
8 months ago
I have never seen a syntax highlighter for SQL that actually covers the real deal from Postgres dialect. Basic stuff is covered and then suddenly you use a combination that isn't covered and the colors are all wrong. This is even true for pgadmin, which is ironic. Unlike most programming languages, SQL built in syntax is huuuuuge and it is very hard to cover it all, especially as it varies with the dialect.
dagss
8 months ago
I use Jetbrains and there is at least full coverage for MSSQL in my experience, which is a huge dialect -- not only syntax highlighting but full IDE features like autocompletion and target name refactoring etc.
And 10 other dialects are listed..
emmelaich
8 months ago
Maybe it's time for programming languages for use something like markdown in strings for embedded sql and dsl. e.g.
```sql
```
eddd-ddde
8 months ago
Any jetbrains IDE with sql tools will work perfectly in my experience.
vlvdus
8 months ago
That would be a nice change too. Also THEN, BEGIN, END to replace varous brackets.
harterrt
8 months ago
Agreed. Fwiw, Mozilla’s style guide prohibits rivers like this.
Izkata
8 months ago
I find splitting out over lines like that harder to read because the table-like columns now overlap with each other and aren't aligned with the keyword they belong to.
user
8 months ago