Live data from Hacker News

PgFormatter: A PostgreSQL SQL syntax beautifier

github.com

11–20 of 33 posts

Re: PgFormatter: A PostgreSQL SQL syntax beautifier

#12

Do we need to use caps for SQL keywords? My understanding is that it served a purpose back in the days of monochrome screens, but modern IDEs colour the keywords so caps are now redundant. Though I don't use caps even without colouring, I find them just a nuisance.

No, not at all. SQL is case agnostic unless you're talking about field collations or, in many systems, object names. It's also largely whitespace agnostic. Many RDBMSs will handle this just fine:

  select*from"MyTable"where"column"=3

Re: PgFormatter: A PostgreSQL SQL syntax beautifier

#14
I'll have to see if I can adapt this to my somewhat idiosyncratic syntax:

  SELECT field, other_field
    FROM table
   WHERE some_thing IN (
         SELECT id 
           FROM other_table
         )
     AND other_field IS NOT NULL
(mostly it's right-aligning keywords, but there are a few other weird tweaks)

Re: PgFormatter: A PostgreSQL SQL syntax beautifier

#16

I'll have to see if I can adapt this to my somewhat idiosyncratic syntax: SELECT field, other_field FROM table WHERE some_thing IN ( SELECT id FROM other_table ) AND other_field IS NOT NULL (mostly it's right-aligning keywords, but there are a few other weird tweaks)

I do similar, keeps both keywords and fields vertically aligned.

Re: PgFormatter: A PostgreSQL SQL syntax beautifier

#17

I'll have to see if I can adapt this to my somewhat idiosyncratic syntax: SELECT field, other_field FROM table WHERE some_thing IN ( SELECT id FROM other_table ) AND other_field IS NOT NULL (mostly it's right-aligning keywords, but there are a few other weird tweaks)

sql-indent for Emacs supports that: https://github.com/alex-hhh/emacs-sql-indent

Re: PgFormatter: A PostgreSQL SQL syntax beautifier

#18
Am I the only one irked by the concept of beautiful SQL? SQL is beautiful by itself. Pick a style (indents,caps,whatever) that fits the project at hand. I have found it useful to write the more mundane parts of a project like a regular paragraph with minimal whitespace, and do more whitespace in areas that are more complex or more likely need attention later. Depending too much on a standard style (ironically) lends itself to some pretty ugly code, eg. tangling too many joins and subqueries that would be far better handled by separate statements.

Re: PgFormatter: A PostgreSQL SQL syntax beautifier

#19

Do we need to use caps for SQL keywords? My understanding is that it served a purpose back in the days of monochrome screens, but modern IDEs colour the keywords so caps are now redundant. Though I don't use caps even without colouring, I find them just a nuisance.

Depends on your IDE. My editor only picks up SQL in strings sometimes.

Re: PgFormatter: A PostgreSQL SQL syntax beautifier

#20

I'll have to see if I can adapt this to my somewhat idiosyncratic syntax: SELECT field, other_field FROM table WHERE some_thing IN ( SELECT id FROM other_table ) AND other_field IS NOT NULL (mostly it's right-aligning keywords, but there are a few other weird tweaks)

I do similar, keeps both keywords and fields vertically aligned.

I do too, but it breaks down on me for some specific:

* ORDER BY

* INNER JOIN

etc

Post reply on HN