Live data from Hacker News

Friendlier SQL with DuckDB

duckdb.org

61–70 of 134 posts

Re: Friendlier SQL with DuckDB

#61

I love the attitude towards ergonomics over standard compliance. And you'll see why SQL has never been really portable across databases ;-)

Maybe if SQL was a better language at the start, there would be more incentive to follow the spec.

SQL is an amazingly good language for what it does. It has been with us coming up on 5 decades.

Re: Friendlier SQL with DuckDB

#62
post #58
post #2

Lots of great additions. I will just highlight two: Column selection : When you have tons of columns these become useful. Clickhouse takes it to the next level and supports APPLY and COLUMN in addition to EXCEPT, REPLACE which DuckDB supports: - APPLY: apply a function to a set of columns - COLUMN: select columns by matching a regular expression (!) Details here: https://clickhouse.com/docs/en/sql-reference/statement…

Yes, trailing commas should work everywhere! JSON is the other one where it annoys me, but luckily I rarely hand-write any JSON anymore (and there are semi-solutions for this like json5). In code I always add trailing commas to anything comma-separated. It makes editing simpler (you can shuffle lines without thinking about commas). In a diff or blame it doesn't show adding a comma as a change. SQL is the one spot whe…

JSONC allows comments and trailing commas, but adoption seems to be low.

VSCode uses it for configuration, but when I wanted to use it in Python (to add context to source-controlled Elasticsearch schemas) there were only a couple old barely-maintained libraries for parsing.

Re: Friendlier SQL with DuckDB

#63
post #10
post #2

Lots of great additions. I will just highlight two: Column selection : When you have tons of columns these become useful. Clickhouse takes it to the next level and supports APPLY and COLUMN in addition to EXCEPT, REPLACE which DuckDB supports: - APPLY: apply a function to a set of columns - COLUMN: select columns by matching a regular expression (!) Details here: https://clickhouse.com/docs/en/sql-reference/statement…

Allow referencing columns defined previously in the same query would make duckdb competitive for data analytics. Without that one has to chain With statements for just the tiniest operations. select 1 as x, x + 2 as y, y/x as z;

(nothing to do with DuckDB but..) SQL is complex enough, and allowing this (and acyclically as mentioned below) would do my $%^& nut implementing it.

But I know a user requirement when I hear one, so can you give me an large, real example of where allowing this would make things easier? That would be mega helpful, ta

Re: Friendlier SQL with DuckDB

#64

I love the attitude towards ergonomics over standard compliance. And you'll see why SQL has never been really portable across databases ;-)

Maybe if SQL was a better language at the start, there would be more incentive to follow the spec.

IIRC there was am ANSI/FIPS standard which was dropped under the bill clinton's administration, which is when things started to diverge.

(Info from memory, may be wrong or a bit mangled)

Re: Friendlier SQL with DuckDB

#65

Earlier quoted context omitted.

Maybe if SQL was a better language at the start, there would be more incentive to follow the spec.

SQL is an amazingly good language for what it does. It has been with us coming up on 5 decades.

Minus everyone having different versions of it to facilitate the missing functionality/needs of users

Re: Friendlier SQL with DuckDB

#67
This looks a little odd

   SELECT age, sum(civility) as total_civility
   FROM star_wars_universe
   ORDER BY ALL
   -- ORDER BY age, total_civility
there's no GROUP BY?

edit: (removed edit, I blew it, sorry)

Re: Friendlier SQL with DuckDB

#68
post #49

If anyone is interested in improvements to SQL, checkout PRQL https://github.com/prql/prql , a pipelined relational query language. It supports: - functions, - using an alias in same `select` that defined it, - trailing commas, - date literals, f-strings and other small improvements we found unpleasant with SQL. https://lang.prql.builders/introduction.html The best part: it compiles into SQL. It's under development,…

This is neat. Have you found this new found capability at odds with "good SQL"? Eg, i run a fairly large application that has a huge DB schema, and more often than not when the SQL gets huge and ugly it often means we're asking too much of the DB. "Too much" being more easy to run into poor indexes, giving more chances for it to pull in unexpectedly large number of rows, etc.

My fear with PRQL is that i'd more easily ask too much of the DB, given how easy it looks to write larger and more complex SQL. Thoughts?

Re: Friendlier SQL with DuckDB

#69
post #2

Lots of great additions. I will just highlight two: Column selection : When you have tons of columns these become useful. Clickhouse takes it to the next level and supports APPLY and COLUMN in addition to EXCEPT, REPLACE which DuckDB supports: - APPLY: apply a function to a set of columns - COLUMN: select columns by matching a regular expression (!) Details here: https://clickhouse.com/docs/en/sql-reference/statement…

You can do the same thing with your WHERE clause and ANDs by always starting them WHERE 1=1 as well.

>> Allowing for trailing commas should get included in the SQL spec.

So there is no "SQL spec" per se, there's an ANSI specification with decades of convention and provider-specific customizations piled on top. This support for trailing commas is the best you're going to get.

Re: Friendlier SQL with DuckDB

#70
post #58

Earlier quoted context omitted.

Yes, trailing commas should work everywhere! JSON is the other one where it annoys me, but luckily I rarely hand-write any JSON anymore (and there are semi-solutions for this like json5). In code I always add trailing commas to anything comma-separated. It makes editing simpler (you can shuffle lines without thinking about commas). In a diff or blame it doesn't show adding a comma as a change. SQL is the one spot whe…

JSONC allows comments and trailing commas, but adoption seems to be low. VSCode uses it for configuration, but when I wanted to use it in Python (to add context to source-controlled Elasticsearch schemas) there were only a couple old barely-maintained libraries for parsing.

> there were only a couple old barely-maintained libraries for parsing.

Do they work, though? If it’s a mostly stable standard, doesn’t seem like you’d need a frequently updated parser.

Post reply on HN