Hacker News new | ask | show | jobs
by richbell 1239 days ago
> Tab! Tab! Tab! PostgreSQL demonstrates its field autocomplete feature.

SELECT preceeding FROM is such a thorn in the side. :(

2 comments

Agree, I started paying attention to duckdb when it started allowing FROM before SELECT https://github.com/duckdb/duckdb/pull/5076
I appreciate the command first syntax, but maybe something like

; SELECT FROM sources ... WHERE / ORDER / ETC ... DATA fields ...

What if DATA was a reserved keyword for column identifiers and other data fields that would normally be immediately after SELECT so they could appear anywhere in the query syntax?

I wish SQL did not require a comma between items after the SELECT and before the FROM. We don't need commas in between joins. I feel like someone could write a way to parse queries so that it isn't needed.

Can you imagine how much time and effort that would save people?

Edit: You do need commas in ORDER BYs, that slipped my mind when typing out this pet peeve of mine.

I'd be happy if it just accepted a dangling comma so you can swap your columns around freely without causing a syntax error
When you see queries written like:

  select
  1
  ,field1
  ,field2
  ,field3
  from ...
you've hit peak SQL engineer comma frustration workaround.
But, what would the token be? Where clauses are separated by AND and OR. Order by are separated by commas. Joins are separated by JOIN, INNER JOIN, AND, etc. The parser knows where the WHERE clauses are because they see the WHERE token.
> I wish SQL did not require a comma between items after the SELECT and before the FROM.

> Can you imagine how much time and effort that would save people?

I can imagine how much extra time I’d spend typing “AS” in queries, which would ne necessary for column aliases to be distinct from new select items. And how much more time I’d spend reading unreadable queries in contexts like logs where they aren’t pretty-printed. Net, it seems to be a big loss.

> We don’t need commas in between joins.

That’s because each join is introduced by a string of one or more reserved words (including JOIN).

If each select field was prefaces with FIELD you wouldn’t need commas, but...

That wouldn't be possible to parse, because of how column aliasing works: the "AS" keyword is optional. In other words, "SELECT foo something_else" is equivalent to "SELECT foo AS something_else".

Also, I seem to recall that very old versions of Oracle did require commas between joins. (The join conditions had to be stated in the WHERE clause back then, instead of supporting the ON clause, iirc).

You can use commas between tables perfectly well. The `join` token just has the same role as the comma, making it redundant.