7 ms·
Things I want in a modern relational query language
- bastawhiz 2mo agoAs a meta comment, I can handle code blocks without syntax highlighting, and I can handle code blocks that wrap. But both together with long comments just turn into line noise. There's no longer any useful visual signal for how to read them. On my phone the code blocks are simply impossible to meaningfully parse.
- froh 2mo agolandscape it is not good but okay-ish on my phone display. hth.
- scythmic_waves 2mo agoSome overlap here with some of my favorite essays on why SQL is lacking: https://www.scattered-thoughts.net/writing/against-sql https://www.scattered-thoughts.net/writing/against-sql That particular post ends with a wish-list of items so it's the most similar to the OP. But there are others on the site that I quite enjoy (click on the home icon and search "SQL" on the page). My personal take is that SQL will continue to reign for a long time because of the how monumental the task of replacing it is due to the inherent complexity of databases. LLMs make this worse because they're really good at translating prose to SQL. Now that it matters less how annoying SQL is to programmers, SQL will become more like assembly over time: something mostly computers write because it's complicated for humans to deal with directly. This is deeply ironic given that SQL was ostensibly designed to read like prose, i.e. to be easy for humans.
- ljm 2mo agoRawdogging SQL when you're not a seasoned DB administrator basically makes an arcane art look occult. Most people reach out towards an ORM or query building engine and otherwise don't really go far beyond the basic CRUD, joins, and some simple aggregations with groups. Since they try to be DB agnostic you'll rarely get an adaptor over CTEs or window functions or partitioning. An LLM is great at exposing what a database is capable of doing with SQL and might even manage to navigate the most poorly designed of schemas. And it might even manage to design one to an acceptable standard if it has enough domain knowledge in its context.
- vjvjvjvjghv 2mo agoThe problem in my view is that there aren't good tools to debug advanced SQL stuff within the context of the whole system which is usually written in a higher level language. I just spent a few weeks modifying some code where the original dev put a lot of logic into stored procedures. That's in principle fine but it's really hard to figure the actual business logic when it's spread out over C# and then also SQL. It doesn't help that the SQL code looks like FORTRAN code from 1985. Personally I think we need ORMs that allow expressing advanced SQL stuff with other high level languages. Or even better: The ORM detects where advanced SQL makes sense and uses it.
- ljm 2mo agoIf I had to pick, I'd try to make the ORM redundant by making 'lower level' SQL easier to deploy rather than depending on sending strings of SQL queries and mutations over the wire. I haven't worked in a single setup where raw SQL has been encouraged, because it always requires DB migrations and not all of them are safe. Nobody dares touch the DB server's resources by setting up stored procedures, materialised views, etc. etc. and instead people are blowing money on Redis instances and caching and shit. I don't have an answer to this but I've hit a lot of issues in my career where I think, "this could have been solved months ago by pivoting a couple of tables or creating a new function." You have been able to 'script' the DB for decades but you lose a lot of what you gain from the traditional SDLC at the app layer.
- grebc 2mo agoDapper in .net is fantastic to deal with raw sql, to the point I think I’m delusional because it’s so damn simple to send outrageous queries to the database and have those multiple mixed results turned into objects very simply. I’ve never had an issue of raw SQL requiring migrations? Unless you’re talking of changing database engine? In which case I think it’s a bit of folly to imagine changing the database engine will not mean changes to your stack higher up the chain.
- bruce511 2mo agoFor me, one of the primary benefits of ORMs is that they can parameterize requests which then prevents SQL injection attacks. Passing raw SQL to the database needs very careful attention to the dynamic parts, and it's too easy for user-generated data to be included. Yes, it's possible to pass user generated text through a sanitizer but now you just have an arms race between the sanitizer and "clever" users.
- reitzensteinm 2mo agoLLMs are also very good at writing code for newly invented languages, especially if they can execute it and iterate. I strongly believe the barrier to switch languages is lowered in a post LLM world. Ten years ago I was at a startup where we used Datomic, and it was okay, but six months in the sales team was like “ok how do I run SQL queries so I can triage leads”. We had no answer of course. Today it would simply be: type what you want in natural language and we’ll generate the query with Claude. I just tried one representative query from that startup against a hypothetical datalog query tool in Rust and it did just fine.
- scythmic_waves 2mo agoI agree that an LLM could also generate the code for a new query language. But my point is that fewer people will attempt to author a new query language in the first place because an LLM will be writing the queries either way. So the effort would be less impactful.
- reitzensteinm 2mo agoYou're right, I was talking past you. I have an implicit belief that SQL isn't the most effective low level language we could have and LLMs will free us up to explore that space, similar to asm.js -> WASM. But I'm open to being wrong about that.
- alliao 2mo agoI think it strikes a good balance between still human-readable and low-ish.. any lower I suspect you'd need to dedicate a lot more documentation else where..
- huahaiy 2mo agoDatalog exists and there are so many implementations.
- huahaiy 2mo agoAgree. Especially when Datalog queries are simpler to write and faster to run than SQL, there is a strong reason to at least try it.
- Rendello 2mo agoThe end of that article ends with a pertinent quote [1] by Michael Stonebraker [2]. I've included more of the original quote here: > My biggest complaint about System R is that the team never stopped to clean up SQL. [...] All the annoying features of the language have endured to this day. SQL will be the COBOL of 2020, a language we are stuck with that everybody will complain about. > My second biggest complaint is that System R used a subroutine call interface (now ODBC) to couple a client application to the DBMS. I consider ODBC among the worst interfaces on the planet. To issue a single query, one has to open a data base, open a cursor, bind it to a query and then issue individual fetches for data records. It takes a page of fairly inscrutable code just to run one query. [...] Only recently with the advent of Linq and Ruby on Rails are we seeing a resurgence of cleaner language-specific enbeddings (sic). 1. http://www.redbook.io/ch2-importantdbms.html http://www.redbook.io/ch2-importantdbms.html 2. https://en.wikipedia.org/wiki/Michael_Stonebraker https://en.wikipedia.org/wiki/Michael_Stonebraker
- wredcoll 2mo agoI was with him until he mentioned Ruby on Rails, is he talking about something other than the fairly ugly activerecord pattern?
- deleted 2mo ago[deleted]
- a2ff6eeb0 2mo agoThis would have been interesting about a decade ago, but today AIs all know SQL, and I haven't written it myself in a while. Since it seems like the quantity of training data dominates AI performance, and AI doesn't yet internalize experience with new tools, it seems like a bad idea to stray from the training set. Without repeatable benchmarks, it feels like obsessing over a language's syntax and semantics feels a little like debating whether you write assembly using AT&T or Intel syntax.
- ModernMech 2mo agoAIs would benefit from better query languages for the same reasons people would.
- a2ff6eeb0 2mo agoThe difference is that the bulk of what an AI knows is baked in when it's trained, at least for now. There's no way for it to learn a language and improve with it.
- ModernMech 2mo agoThat's not quite true in my experience; AI can pick up new languages very quickly and are able to adapt to novel syntax and semantics with just a description and a few examples. What's also baked into the AI are decades of PL research and it can quickly deploy esoteric PL concepts not found in 99% of languages. In my experience it's rather people who have the most trouble with new languages, as the difference between the PL frontier and languages that most people use is quite extreme. Conversely, AI is adept at staking out a point in the PL design space and developing a grammar and vocabulary around it. Then it writes a parser and interpreter to execute whatever semantics, writes a standard library to support writing programs, and finally writes the compiler in itself. Because it's so good at doing this you can do a lot of exploration whereas before it would take years now it takes months.
- a2ff6eeb0 2mo ago
- esafak 2mo agoDatabase engineers have to be the change they want to see and add support for newer query languages.
- convolvatron 2mo agothat is a pretty difficult place to apply leverage. if you don't support SQL you're at a big competitive disadvantage. because its a weird design with lots of sharp edges that's going to take a lot of your time - customers are going to be unhappy that you don't support the knobs and frills from their existing environment. so you can certainly float an alternate QL on top of the same base, but its going to be hard to drive uptake. you can translate SQL to your internal variant, but oddities like group by are going to twist your internal model. at this point I think its more interesting to start to deconstruct these large software systems like OSes and databases and move the composition of systems down a step.
- flir 2mo agoThe early-2ks crop of NoSQL solutions have all got SQL baked in now, haven't they? Maybe when they've achieved wide adoption for a better language than SQL, they can work on getting rid of qwerty keyboards...
- mcc1ane 2mo agohttps://www.geldata.com/blog/we-can-do-better-than-sql https://www.geldata.com/blog/we-can-do-better-than-sql (https://news.ycombinator.com/item?id=24106608 https://news.ycombinator.com/item?id=24106608, https://news.ycombinator.com/item?id=19871051 https://news.ycombinator.com/item?id=19871051)
- bri-holt 2mo agoThis is an ultra compact relational query language designed for LLMs. https://memelang.net/11/ https://memelang.net/11/
- a2ff6eeb0 2mo agoWhat benchmarks did they use? It seems like on larger tasks, having the LLM be familiar with the language through a large volume of training data will compactness and tenseness. See https://danluu.com/pl-tokens/ https://danluu.com/pl-tokens/
- zoolo 2mo agoCheck out CodeQL, it's a modern relational query language based on Datalog.
- 3eb7988a1663 2mo agoCan someone explain to me why SQL error messages are so bad? I routinely have some monster query where the message is effectively, "Illegal syntax somewhere, dufus".
- klysm 2mo agoThis sounds like a proper of the parser, rather than of the language
- derriz 2mo agoA long time ago, I had to write SQL parsers (for 3 of the most popular DBs at the time). It is a surprisingly difficult language to parse and disambiguate - particularly when having to deal with the warts of its variants. Sure it's not quite C++ but it's was easily the most annoying parser work I ever had to do. And in my experience, the trickier it is to parse a particular language, the more difficult it is to provide feedback to users in the form of helpful parse errors.
- appplication 2mo agoThis is true, but the observation is still salient. There does seem to be some correspondence between languages with inherent friction and parsers that aren’t interested in being helpful. E.g. sometimes a user base just collectively decides they’re ok with some level of pain.
- bawolff 2mo agoI'd guess people just haven't put much effort into it. Lots of programming language compilers have absolutely terrible error messages. In SQL its usually just one line, so "somewhere" isn't that big a place.
- tmoertel 2mo agoThe problem with alternative query languages is that the people who have the most knowledge about creating queries and of the relational domains underlying their businesses are all experts in SQL. Introducing something else, then, means your most natural user base must migrate away from something they understand how to use well, and that's a hard sell. So, until the ultimate query language is developed, I'll take SQL with pipes. It's an easy sell and good enough to eliminate 90% of my gripes about SQL.
- taybin 2mo agoThis is exactly the same problem facing people trying to develop new music notations. In order to grasp the domain enough, they have to be experts in the existing music notation, and once you're an expert in it, the motivation to create something new goes away. From what I've seen, the people who want a new music notation are mostly people uncomfortable with sight reading.
- AlotOfReading 2mo agoExperts have been criticizing SQL since it was a proprietary IBM language. Take this typewritten rant from 1983 [0] as an example. And we've had better query languages for just as long, e.g. datalog. People really love SQL though, which I can only assume is because the vast majority of usecases are slight variations on SELECT * FROM table. [0] https://courses.cs.duke.edu/spring03/cps216/papers/date-1983.pdf https://courses.cs.duke.edu/spring03/cps216/papers/date-1983...
- g-b-r 2mo agoI hardly doubt that many people love SQL They might love the relational model concepts that manage to seep through it
- smitty1e 2mo agoFor example, Elastic. Much extra learning curve for little obvious gain. I like to say, with zero research basis, that the New Shiny has to be an order of magnitude better than the Old Thing for people to say "Oh yeah, I gotta have that."
- avmich 2mo agoWhy don't we have APL as the language here?
- senfiaj 2mo agoI wan't easier ways to work with nested structures, like relationships. All this flat table structure is a pain.
- convolvatron 2mo agothe only real differences between a query language and a normal language are quantification and unification. quantification is something that seems pretty easy to paper over (i.e by just having functions that operate on Set types). SPJ is/was working on a lanauge Verse which provides a procedural looking language that is actually either fully unification or region-based under the hood. trivially this is just allowing relations (tables or functions) to implement only a subset of input/output signatures so yes, I think its a great idea to just smoosh the two together, particularly if its in a host language with sufficient meta programming facilities to extract out the relational parts and evaluate them as streams
- burakemir 2mo agoI would be genuinely curious what the OP other and folks here think of Mangle Datalog in this context. The go implementation is here: https://codeberg.org/TauCeti/mangle-go https://codeberg.org/TauCeti/mangle-go and the Rust implementation is here: https://codeberg.org/TauCeti/mangle-rs https://codeberg.org/TauCeti/mangle-rs The implementations are not high performance, but if you can fit everything in memory or you can organize your data and integrate it through external queries, you should get something workable for a lot of use cases. I did not set out to replace SQL, and while I don't mind adoption, that is not why I am sharing it here. The open sourcing was motivated by making datalog more widely known. I did some research and found out that I needed a datalog implementation with particular characteristics, I for sure knew I didn't want to use SQL for what I needed. There are structured types and recursion and being able to name predicates and compose queries... Mangle has some users and there is a few application that take advantage of the queries-as-logic-programming approach. I think an insight one can draw in this discussion that a query language and the system (DBMS implementation) that it is part of can hardly be separated when it comes to the inevitable performance requirements one has.
- AlotOfReading 2mo agoThat's a pretty cool pair of repos. I've been working on a C++ Datalog myself [0] for embedded queries over in-memory datasets. It's been surprisingly useful for a bunch of different usecases (e.g. build graphs). My implementation is faster than Souffle on all the benchmarks I've tried, but apparently I still have some work to do optimizing startup time on small graphs. [0] https://github.com/J-Montgomery/dartfrog https://github.com/J-Montgomery/dartfrog
- YuechenLi 2mo agoSQL is what it is today because it is battle tested and has to handles a very hard problem of handling arbitrary concurrent reads/writes, so the likely scenario is that trying to replace general SQL wholesale will just end up making a worse, less tested version of SQL that developers are less familiar with. So, I think the best query language is probably whatever query feature that's already in your backend language, LINQ for C# for example. The only room for an SQL replacement in my opinion is if you are willing to trade flexibility for speed a la TigerBeetle. The good thing about having built your own programming language via LLM nowadays is that you don't really have to speculate about a theoretical language when you can just have Codex/Claude implement it and try it out for yourself. I did it yesterday when I wanted to try out this theoretical high-performance database architecture that I had in mind and just added query functionalities to the language I already have. If anyone is interested about the results, the default naive mode for this new database is ~0.2x the speed of concurrent durable mutation workloads, but if you specialize it to the particular application, you can get ridiculous 50-100x performance increases on filters and maps at the cost of flexibility and more upfront design. Experimental results are promising, definitely not production ready though.
- calvinmorrison 2mo agodoesnt meant the syntax isnt a pile of dog farts
- Southclaws 2mo agothis is exactly why i built Rad: a relational db with an IR as its public interface, so you can experiment with interesting query languages against a solid foundation and a real planner without needing to compile-up to sql (radengine.dev)
- crabmusket 2mo agoOh this is awesome. This is exactly what I've been too lazy to build for years now. We don't need a new syntax. SQL, PRQL or whatever else should compile down to the database's machine readable interface, same as language-integrated query builders or libraries like your generated clients. Did you come across Substrait when working on this? Any thoughts? This also sounds like what Turso imagine doing with their VDBE: > Like SQLite, it compiles SQL into bytecode for that machine, the VDBE, and then runs the bytecode. That design is what lets one engine host more than one SQL dialect. SQLite is the first and primary frontend that compiles to it, and Postgres is now a frontend of its own, with its own dialect and wire protocol. More will follow. Our goal is to be for databases what LLVM is to compilers, with one modern and reliable core, and many frontends compiled down onto it.
- ravimakhijapi 2mo agoI think part of the issue is that SQL is nice for some things (do some aggregation on a row-filtered subset of columns) but perhaps not as much for other things (a query where later rows depend on earlier rows in complex ways). I think being able to compile a procedural programming language to SQL would be pretty nice for the latter.
- NetMageSCW 2mo agoSee LINQ?
- mrkeen 2mo agoI love LINQ's syntax and monadic API, but that's about it. It speed-runs juniors into thinking they are writing transactional code when they aren't. And for seniors who are more aware of footguns and try to be careful, they're met with an inability to do so (e.g. upserts).
- veqq 2mo agohttps://codeberg.org/veqq/declarative-dsls https://codeberg.org/veqq/declarative-dsls is like LinQ turned to ~11~ 50.
- speedstyle 2mo agoI don't want a query language. I want to call and profile typed functions like normal data structures, and which use (low-level/non-declarative) RPC where needed
- zbentley 2mo agoI don’t think that extreme is compatible with the reporting/analytics use case of SQL DBs. Even though entire roles/companies may never touch that kind of SQL, there’s a massive quantity of it out there. I once worked on a medical records system (with a pretty well designed but necessarily complex schema) where the primary “patient” data object used by most code was fetched by a query that, depending on what associated data you needed, had between 106 and more than 400 relations (across dozens to hundreds of tables) joined together. And that was CRUDy data-path code. The OLAP/reporting side added zeros to those numbers. Query texts were often hundreds of kilobytes.
- speedstyle 2mo agoCould the same queries be 'planned', compiled down to pipelined KV operations, by the requester? I don't see that this is inherently less capable. You could even use an existing ORM – though I think you can do better when not compiling to something declarative, maybe more like polars. I feel like databases effectively (/literally) add a JIT, which can mostly figure out what to do, even has accurate heuristics on the distribution of the data, but in exchange you get a less deterministic system, and less intuition for how to query or structure things. It's like, you know when to use a list/map/queue, but you want to focus on the business logic, so just use a smart collections which guess at runtime. I think you can get this with FoundationDB, I should experiment rather than hypothesizing, but it feels like it would be nicer
- zbentley 2mo agoIt’s theoretically possible to do that kind of planning on the client, but difficult and not worth it compared to letting the database do it. Especially for reporting, there’s another disadvantage: many query planners use runtime statistics from the database to build the plan; synchronizing those onto the client would be difficult and error-prone. But why bother? If I have a thousand clients that all want to run a query, why compile the plan a thousand times (and build/distribute the local planner to all of the different clients’ platforms) when I could send a query and have the database plan and cache the query once?
- nylonstrung 2mo agoPRQL is one of the best attempts at a new query language IMO I've been working on a Lean4-based query lang that compiles to substrait, I think the power it has wrt to types and functional programming could improve on SQL ergonomics a good deal
- mikewarot 2mo agoMy ask is 15 years old[1], a live SQL extension. Allow a query to be a subscription to a database, so any updates get streamed as deltas to a listening client. There were a ton of times in my time using SQL where the same query is run over and over, just to get/handle that delta. Wouldn't it be a lot more efficient to just work that way in the first place? [1] http://livesql.org/ http://livesql.org/ <--- just a few paragraphs of text from 2011
- convolvatron 2mo agopg logical replication is close to this. but ideally you want incremental query updates, which I believe Materialize provides. but yes, I agree this is quite often what one wants, and would remove a lot of grot from the client
- mike_hearn 2mo agoBTW, Oracle supports this under the name "continuous query notification". https://docs.oracle.com/en/database/oracle/oracle-database/26/adfns/cqn.html https://docs.oracle.com/en/database/oracle/oracle-database/2... You can get callbacks from the driver as query results change, or have notifications be sent to stored procedures, or posted to a message queue (and from there turned into web hooks etc). The notification comes with info about the deltas. The main issue with it is that the queries it can monitor live are a subset of all queries. It's really more like using SQL to select database cells to watch, than propagating changes through arbitrary query plans. For example, it can't handle a SELECT COUNT(*) FROM statement. Obviously you can use it as a trigger for re-running more advanced queries though.
- DenisM 2mo agoSnowflake has STREAM which can be crated on a view. It also has Dynamic Tables, from which you read a delta using STREAM or using row timestamp. SQL server has Query Notification. You can also read from debezium or other cdc, but thats more like table change than query result change.
- gregw2 2mo agoAnd Bigquery has continuous queries: https://docs.cloud.google.com/bigquery/docs/continuous-queries-introduction https://docs.cloud.google.com/bigquery/docs/continuous-queri... And many databases have triggers. And with postgres you can combine triggers with NOTIFY to push changes downstream. But yeah, I feel like most databases are way behind Oracle on this feature and it's so so useful.
- gonzalohm 2mo agoNothing around better error handling or schema updates? After working with SQL for 10+ years those are definitely the things I miss. For error handling I mean things like deprecating a column and allowing a custom error message when someone queries it. And for schema updates I mean allowing table versions. Same table name but allowing querying an older version of the schema
- grebc 2mo agoI like the idea of deprecating a column and getting a warning so much. Also versioned data built-in I would love.
- brianolson 2mo agoSQL is the worst way to access a database, except for all of the others that have been tried from time to time
- UltraSane 2mo agoCypher is pretty nice.
- weitendorf 2mo agoSounds a lot like Spark before it became so enterprise-focused. Back in my day we wrote scala to run our queries, and once we figured out how to get our compiler and runtime set up, we liked it! I’ve been getting into Postgres recently and I was very surprised how easy it is to introduce new types/operators/etc through C code. I’m not talking about domains. Just write some C and you can have whatever type you want. It really demystified “extensions” for me, I actually think that is an actively harmful name (it sounds clunky, gross, based on my experience dealing with “extension” and “plugins” elsewhere) for what is essentially just custom types/functions. More people should try writing their own postgres extensions. It’s not very difficult at all! I’ve been cooking in this space for quite a while (HDFS/spark, Apache Pinot, proprietary stuff, an experimental functional ORM over SQLite). The biggest problem, I think, is the interface between the management/admin, application, and “query” layers. I think something like grpc/protoc (or indeed the way Spark used the JVM) is needed to provide non-leaky abstractions and more programmatic/structured interfaces from the DB to its clients. Happy to share more, but basically, the database needs to become capable of general (meta-)parsing with a reflective type system, I think.
- dzonga 2mo agofor most 'application' like workloads not analytics - standardizing or improving on mongo-query language (MQL) would be welcome. the drawback is your query patterns have to be known before hand when designing your application. which isn't really a drawback since you're doing it before building the application. & hence not as flexible as SQL.
- huahaiy 2mo agoDatalevin seems to fit the bill https://datalevin.org/docs https://datalevin.org/docs First paragraph of preface: “SQL has been the default language of application databases for half a century. That default is now holding application state back. Datalevin is a database built to replace SQL databases at the center of application systems: it stores data as small facts and queries those facts with Datalog”
- justanothersnek 2mo agoI've tend to use both SQL and a dataframe API library. I guess it is sort of a a best of both worlds. SQL for the high level, large aggregations, dataframe library for when the equivalent SQL statement would be very tedious or hard to debug.
- BrenBarn 1mo agoWhat I want from a query language is for it to not be a language, but some kind of specification of components that can then be transmitted to the engine in a machine-readable way. The bizarre thing about SQL is that it has to be written in SQL. What if instead a JSON representation of the query (something akin to the AST, with a bit of processing done to boil it down) is what the engine took in? Then each language could specify the query in whatever syntax is most idiomatic for that language. Right now we do this with ORMs, but it's a huge pain because the ORMs are like a transpiler with a really free-form and messy language as the target. All the ORMs are just pasting strings together. If the "native" query format were more structured, we could have a lot more cool approaches for wrapping that on the programmer-facing side.
- nigwil_ 1mo agohttps://github.com/dataphor/Dataphor https://github.com/dataphor/Dataphor