News for hackers. Stuff that matters.
Re:I don't need your query language by ako on Saturday June 17, 2023 @07:18AM (#36369183)
Always start with the end in mind, first what your goal is then how to achieve it.

Also, i don't actually see the problem because you never write a query in a lineair way. Usually start with "select * from table limit 10", look at the columns and data available, and then start refining. By now, code completion works as the table is known. Wouldn't help much to write it table first.

Re:I don't need your query language by LunicLynx on Saturday June 17, 2023 @07:30AM (#36369279)
Exactly, you could actually drop the `select` in this case and just say `from table limit 10` don't state what you don't need.

What you describe is learned behavior to get along with a design flaw. SQL won't change, so no reason to worry.

My point is: People keep creating new versions of it, because it is not as `easy` to work with as it could be.

Re:I don't need your query language by ayhanfuat on Saturday June 17, 2023 @07:34AM (#36369306)
That's valid DuckDB syntax
Re:I don't need your query language by mcdonje on Saturday June 17, 2023 @08:14AM (#36369562)
DuckDB has some really nice syntax updates that I hope get added to the ISO spec, like GROUP BY ALL and GROUP BY aliases.

I like their approach of adding thoughtful quality of life improvements instead of coming up with a new language.

https://duckdb.org/2022/05/04/friendlier-sql.html

Re:I don't need your query language by zX41ZdbW on Saturday June 17, 2023 @08:43AM (#36369729)
Most of the improvements in the article, including unrestricted aliases, were added in ClickHouse and subsequently influenced DuckDB. They still have to implement many usability and language improvements from ClickHouse.
Re:I don't need your query language by mcdonje on Saturday June 17, 2023 @09:06AM (#36369871)
Didn't know that, thanks.
Re:I don't need your query language by magicalhippo on Saturday June 17, 2023 @08:52AM (#36369783)
> GROUP BY aliases

We're migrating from Sybase SQLAnywhere to MSSQL, and not being able to use aliases in WHERE, GROUP BY and ORDER BY is such a pain in the behind.

Almost all our non-trivial queries have to be nested multiple levels due to this, which doesn't exactly help readability.

Re:I don't need your query language by bavell on Saturday June 17, 2023 @08:58PM (#36376306)
Ugh, I'll be having to do this same migration soon for one of my clients. Not looking forward to it. Good to know!
Re:I don't need your query language by fbdab103 on Saturday June 17, 2023 @11:28AM (#36371055)
I would love if base SQL were improved. On the other hand, we are just slapping lipstick on a pig. It is already a gargantuan mess which needs a path to replacement.

Then again, Oracle just this year added support for booleans, so asking the incumbents to switch to a new query language seems an impossible ask.

Re:I don't need your query language by chrisjc on Monday June 19, 2023 @10:06AM (#36391247)
Agreed... Their SQL is awesome and seemingly only getting better.

My favorite is window aliases (I'm sure it's found in other SQL engines too). It's not only cleaner and less likely to accidentally introduce a discrepancy, but apparently also results in better performance.

> The three window functions will also share the data layout, which will improve performance.

https://duckdb.org/docs/sql/window_functions#window-clauses

I'm surprised some of the other big-name OLAPs don't provide this. *cough* Snowflake *cough*. Snowflake's query optimizer doesn't even seem to recognize common window definitions across multiple window functions.

Re:I don't need your query language by ttfkam on Saturday June 17, 2023 @11:18AM (#36370944)
Because the DuckDB folks used the Postgres query parser.

It's been an alternative in Postgres for decades.

Re:I don't need your query language by ttfkam on Saturday June 17, 2023 @11:19AM (#36370967)
In Postgres, it's

   TABLE foo
   LIMIT 100;
No SELECT with columns and no FROM keyword.
Re:I don't need your query language by idoubtit on Saturday June 17, 2023 @08:23AM (#36369614)
> Usually start with "select * from table limit 10", look at the columns and data available, and then start refining.

An experienced person won't do that. For any moderately complex SQL query, before writing it I already have in mind the several jointures I'll need, since I usually know the tables and FK I'm working with. It's like following the edges of a graph, all in my head. But I don't know all the fields of these tables, so I rarely write their names from memory. So I have to write "SELECT 1 FROM …" and then go back to that "1" once my FROM is complete. That's not the end of the world, but it does smell.

Re:I don't need your query language by jmull on Saturday June 17, 2023 @08:58AM (#36369823)
> An experienced person won't do that.

I’m very experienced and do that kind of thing all the time.

Also, your “SELECT 1” technique seems like practically the same thing, except I guess you discover column names from autocomplete tooling rather than query output. (To my mind the difference is inconsequential.)

Re:I don't need your query language by weinzierl on Saturday June 17, 2023 @11:45AM (#36371214)
Me too and I don't even bother with LIMIT 10. However, the "proper" experienced way would be DESCRIBE I guess.
Re:I don't need your query language by marcosdumay on Saturday June 17, 2023 @10:56AM (#36370727)
If you mean a developer with deep and recent experience on the exact tables your query will use, then yeah, this one won't do that.

But if you mean any other kind of experience or expertise, you are wrong. Those do not correlate with how a person assembles a query.

Re:I don't need your query language by ako on Saturday June 17, 2023 @12:05PM (#36371442)
I consider myself experienced, started professionally with sql in 1994 with oracle 6, and it really depends on how familiar you are with the database. I often work with databases I’m not familiar with, so exploring the structure by looking at examples of the data is where I start.
Re:I don't need your query language by kubanczyk on Saturday June 17, 2023 @01:02PM (#36372056)
> have in mind the several jointures

I typically keep all JOINs I've ever used on that schema in a single file, one per line.

Before writing a new query I can just copy paste some JOINs, simply skimming through table names like lego bricks.

That way it's surprisingly easy to beam from domain problem to a new query that uses 10 or 20 tables.

I've just realized that it might be all archaic now, in LLM era.

Re:I don't need your query language by lostdog on Saturday June 17, 2023 @02:14PM (#36372820)
This is a great idea in practice, but it really points to how sql could improve.

You have a library of useful joins that you've checked for correctness. Saving the library as reusable code would be even more useful.