r/programming • • 11d ago

SakaQL: A new general-purpose relational programming language

https://www.saka.io/blog/sakaql-general-purpose-relational-programming-language/

SakaQL explores this idea: can you build a relational programming language that's usable outside of databases and actually nice?

Cool ideas include native incremental view maintenance based on DBSP, set-based types inspired by TypeScript and EdgeQL, a composable regular expression alternative, native parsing inspired by Janet and Raku, and unbounded integers with interval subtypes, and innovative syntax design.

39 Upvotes

36 comments sorted by

32

u/lood9phee2Ri 11d ago

Yeah, SQL was designed to be "english like". You know, like Cobol. So "friendly" that business end-users could just write it instead of those expensive programmers.

The relational model is fundamentally quite pretty with unusually strong grounding in actual mathematical/logical theory. Just obscured horribly by SQL concrete syntax. BUT the fact there's some sort of an actual cross-vendor language standard is good too....

https://en.wikipedia.org/wiki/Relational_calculus

11

u/eejdoowad 11d ago

I think SQL's english-like syntax is one its greatest strengths and weaknesses. Like you mentioned, it made it possible for non-programmers to write simple queries. And that is frequently all that's needed and is probably a major contributor to why SQL is so dominant today.

Problems only arise when you try to write non-simple queries:
- Subqueries and CTEs are poor mechanisms for composition, but composition is how you break down hard problems into simpler approachable ones.
- There are many useful features that most people never learn to use due to syntactic complexity like window functions and correlated subqueries
- Name resolution rules are confusing: why are names valid in certain clauses but not others and why is grouping syntax so brittle?

That said, I acknowledge that it's almost always foolish to use anything besides SQL for practical application due to the maturity of its ecosystem. But maybe one day...

3

u/saastryde 11d ago

The problem is the mismatch between human-readable syntax and relational algebra. You can't reason about set operations intuitively in English-like SQL without getting bitten by cartesian products or null semantics.

1

u/eejdoowad 10d ago

I think SQL NULL might be a bigger problem than SQL syntax. Its existence makes everything from joins to grouping and aggregates to ordering to basic operations unintuitive. EdgeQL showed relational languages don't need NULL, and everything is better without it. I just copied them.

1

u/edwards_t7407 7d ago

Removing NULL avoids three-valued comparisons, but missing data still needs semantics. How does SakaQL handle optional values across joins and aggregates?

1

u/eejdoowad 7d ago

Everything is a bag (unordered multi-set). Empty sets replace NULL in storage and views.

If you declare a variable as def books* (title: str, year: number) then every entry in this bag must have both a title and a year; its invalid for either to be missing. This is different from SQL, where columns of a table may be NULL.

This is where the object model comes in. In SakaQL, you define a role and properties:

role Book
prop Book::title! str // title is required
prop Book::year? int // year is optional

Behind the scenes, this basically represents three relations:

- Book ids
- mappings from Book ids to title strings
- mappings from Book ids to year integers

You can query and mutate roles and properties like you would any other variable. The language is designed to make this ergonomic, but that's a separate topic.

This logical representation doesn't mean the physical representation has to be three separate tables, though that is the case today.

In SQL, you often also return queries with NULL columns and use features like asymmetric joins to specify NULL handling behavior. Scrub that from your memory.

In SakaQL:
- there are no asymmetric joins
- there are no NULLs

Instead, correlated queries are much easier and usually what you want, and instead of writing queries that produce NULLs you write multiple correlated queries that share some common grouping property.

That's something you wouldn't consider in SQL because the ergonomics would be terrible and because SQL database protocols are limited to returning the results of a single query.

Admittedly, there are some cases where not having a NULL value leads to awkward query ergonomics. For example, imagine trying to find the three newest books. Writing this correctly while accounting for the fact that some books don't have year data is tough.

That's why there is, sort-of, a NULL equivalent: the optional wrapper opt(). I discourage its use, but it is useful for writing certain types of queries:

Book
by opt(.year)
last 3
map .v.title

13

u/chat-lu 11d ago

People have tried. EdgeQL was ambitious and promising, but it didn’t work out because it asked users to make an unjustifiable tradeoff: get a better language, but risk your data on unproven technology from a startup, lose compatibility with the wider data ecosystem, and burn time learning something new.

I don't get it, aren't you offering that same trade-off?

0

u/eejdoowad 11d ago

SakaQL targets general purpose programming; it does not attempt to replace SQL OLTP/OLAP databases.

saka.io the in-development data management tool is designed to store data as plain text files in a git repo. SQL is not a viable alternative for this.

6

u/ginrumryeale 11d ago

Looks interesting, however once you cross the boundaries of the CRUD operations SQL was designed for it stops looking like simple, highly readable SQL.

It looks like somone’s fairly ordinary scripting language project influenced by a query language.

2

u/eejdoowad 11d ago

> It looks like somone’s fairly ordinary scripting language project influenced by a query language.

That's actually the goal. The whole idea is to build an approachable language with a relational foundation. The relational foundation unlocks super powers: you get a query optimizer and incremental view maintenance. These are very powerful tools for writing programs that are both performant and ergonomic.

1

u/ginrumryeale 11d ago

I’m excited to explore it.

24

u/josephjnk 11d ago

SQL is good, actually. Not even a hot take to say so.

Maybe SakaQL is good too, though in 2026 my default assumption is that everything new is vibecoded. I’m not really interested to put in the work to dig for what’s worthwhile here when the author spends half of the article trying to dunk on SQL. If someone can’t understand what’s good about SQL then I don’t trust them to try to make something better.

-3

u/eejdoowad 11d ago

It's unwise to use anything but SQL databases for most practical applications.

That said, if I'm going to the trouble of designing and building a new language, I need to explain why SQL was unsuitable.

Try reading the post; it's not vibed and you'll find that <20% is about SQL.

12

u/josephjnk 11d ago

I’d recommend workshopping your post to focus on why SQL doesn’t apply well to the wider range of problems that your language targets, rather than opening up with, literally, “SQL is bad”. If your project isn’t vibe coded then I am cheering for you, but you’re going to lose a lot of traction by opening up with an oppositional and (mostly) false statement.

3

u/eejdoowad 11d ago

Fair point

7

u/chat-lu 11d ago

You say that it's not vibe coded but you also wrote :

Today AI is used heavily in SakaQL’s design and development.

0

u/838291836389183 10d ago

There is a difference between 'Write SakaQL, make no mistakes" and basically using AI as a tool to speed up writing classes, refactoring, writing test cases or as an alternative to googling.

4

u/Wonderful-Habit-139 10d ago

I guess bro…

1

u/Wonderful-Wind-5736 10d ago

Mmm, nice language. I'd much rather write that than SQL. Although I'm not sold on the scripting language side. Generally a good scripting language needs great interop to earn its place, and I'd rather see your unique features be implemented as a Python DSL.  That said if you could actually target SQL, or even better Substrait, that would be pretty hot.

1

u/eejdoowad 10d ago

Compiling to SQL for use in existing databases is possible in theory, but I think you'd run into problems in practice:

- It doesn't add any new capabilities to your database, just different syntax, so it ends up being just another layer of abstraction
- You eventually need low-level control to optimize certain queries, which means you have to drop down to SQL anyway.
- Developing and maintaining an abstraction like this is a lot of work, especially if you target multiple SQL dialects

1

u/manifoldjava 10d ago

Interesting. A bit low-level though for general-purpose: no abstractions to combine behavior and data/records. At least I didn't see that in my scan of your docs.

My ideal general-purpose language for relational models would be interface composition via *true* delegation (ordinary object composition + open recursion). Closest to this is probably traits (Scala), unfortunately traits are not object composition, they are linearized into the inheritance model forcing a single object identity and all its limitations.

1

u/eejdoowad 10d ago

Your assessment that there is no abstraction combining behavior and data is spot on. The closest you can get is colocating variables and roles in the same module as the procedures and functions that operate on them.

I'm not sure I understand your idea.

SakaQL draws a hard line between procedural execution and pure computation. This division allows computation to compile to relational algebra and is what enables the query planner, incremental view maintenance, and efficient recursive views (based on DBSP https://arxiv.org/abs/2203.16684).

SakaQL's object model explicitly does not support inheritance and instead supports instances that belong to multiple roles simultaneously (similar to entity-component systems). My early design for the object model was a hybrid of EdgeDB and TypeDB, and actually supported inheritance, but it proved unworkable; inheritance and SakaQL's type system didn't play well together.

Traits may (or may not) be in the future of SakaQL. There are a lot of design constraints, and it's really hard to combine features. In this particular case it was traits and set-based types.

1

u/manifoldjava 10d ago

I'm not sure I understand your idea.

Pure interface inheritance neatly maps to any normalized relational model, including those intended as is-a relationships e.g., FK/PK subtyping.

Ordinary object composition via forwarding implements the interface hierarchy by delegating implementation to components forming composite objects, completely avoiding implementation inheritance. But this strategy abandons the dynamic dispatch of inheritance. Open recursion is therefore lost, which is in practice necessary esp. when combining behavior with data (the domain model).

As a consequence of its foundational implementation inheritance, traits provide dynamic dispatch, but due to linearization, give up object independence, which constrains the relational models it can support and forces the structure of its composition to compile-time definition. Critically, unlike object composition, trait composition can't be assembled at runtime e.g., via constructor-injected components.

Combining object composition and dynamic dispatch (esp. open recursion) while not compromising either is the sweet spot.

See the proposed Parts delegation model for a clearer picture, albeit without any focus on its suitability for the relational model.

1

u/[deleted] 10d ago

[removed] — view removed comment

1

u/manifoldjava 10d ago

Runtime composition is orthogonal to relational planning. The type of runtime composition I am referring to is the nominal statically typed kind, which requires predetermined data definitions (roles/tables).

In my view the definition and query languages should remain separate, domain-specific languages that integrate neatly with the general purpose language. See manifold-sql as an example of this.

1

u/danielaveryj 7d ago

Hey, just wanted to give some feedback, I saw this post when it came out and have poked around here and there the last few days. I'm looking at this as someone who has now spent considerable time designing their own relational language (for querying / UI, not general scripting), so I'm probably more comfortable thinking in that paradigm than others would be (but I'm sure I have my own hang-ups).

I first want to say this looks brilliant in several ways. I think I'd heard the idea before of modeling cardinality as an axis in the type system, but it felt eye-opening for me seeing the regex quantifiers combined with a component type and a universal bag data structure - so basically, every value uniformly supports querying, while still allowing us to enforce exactly-one / maybe-one / at-least-one of a specific type. I think that's an evolution over EdgeQL's sets, and at least two evolutions over Lua's tables.

It's very cool to hear that you incorporated IVM into the language. Integrated into a general-purpose language, it seems like that would dramatically improve the feasibility of scripting responsive data-intensive interactive apps.

Also, to have all this actually working and running in the browser is incredible.

I do want to talk about your docs, because I feel like they're not selling this as well as they could.

On the introductory page, I felt pulled in initially and was reading intently, but as it went on I ran into more and more hiccups that pushed me to skim. I think the first one was here:

def c = "hi \{"mo", "jo"}" // {"hi jo", "hi mo"}

On a first read, I'm inclined to assume this desugars to two pointwise concatenations: First joining "hi " to {"mo", "jo"}, and then joining that bag to the empty string (that follows the interpolated bag). But up until this point I haven't seen *any* string concatenation or interpolation in this language, so I'm not sure if what I'm looking at really is an "interpolated bag" or means something more context-specific entirely. The actual behavior (which I eventually discovered in the REPL) would be clearer if a non-empty string followed, and clearer still if an example had multiple interpolations, but I'm not given an answer at this point, and now I'm distracted from the simple idea of this section ("Arithmetic expressions are pointwise").

Similarly in the "Recursion" section, three new operators are introduced on one line - yes, I can guess what the result is supposed to be, but I can't decipher how we're getting there. And again in "Native parsing" - I see new keywords, something that looks like a tuple but with a hash symbol before it, something that looks like a bag but with a minus sign before it, something that looks like a reference but with a colon before it, and so on. I know you're trying to show a lot (maybe that doesn't all need to be shown up-front?), but leaving so many unexplained sigils in introductory material gives a feeling that the language has sharp corners.

Of course, I was still drawn in, so I read most of the SakaQL tutorial and reference. This was good, and a lot better at introducing new things gently / carefully, but I really wish examples (or at least individual pages) were more self-contained - assuming a persistent REPL context the whole time makes it increasingly difficult to recall what we're operating on, especially when using these pages as a reference later.

As a side note, I much preferred the syntax that puts the cardinality by the type, rather than the variable name. I spent forever just looking for the syntax to combine a Set + "allowlist" + arbitrary cardinality - I think this is the closest the documentation comes to showing the full-generality syntax.

My overall impression is that this is a really interesting language and an impressive project, and I would like to live in a world where this takes off, but that's hard for me to picture right now. I think part of it is that the commercial pitch - which seems aimed more at data management tools than scripting - feels uncomfortably similar to EdgeQL, and susceptible to the same "boiling-the-ocean" concerns. It wouldn't help that the language is perhaps more complex than theirs, in a domain that overlaps less-technical users, and at a time when even developers' appetites for language innovation are perhaps greatly depressed. On the other hand, you've seemed to emphasize the scripting aspect here, and I do think the language brings something new and exciting to that arena (I would personally love to see more people casually wielding an IVM-backed relational toolkit).

1

u/eejdoowad 6d ago edited 6d ago

I do want to make the language and its ideas more accessible, so I do need to invest in better documentation. Thanks for the pointers!

I'm surprised you preferred the full constraint cardinality syntax over the shorthand. I added the shorthand because I got tired of typing and reading the full constraint syntax. I really thought the shorthand was unambiguously better, but now I'm wondering.

My idea for better data management tools is actually the motivation for SakaQL and not vice-versa. For these tools, I needed a relational language with a more flexible data model than SQL and an implementation supporting IVM. Nothing fit the bill, so I had to make my own language. And if was doing that, I might as well make it a good one.

Designing SakaQL and building its compiler has been a really big endeavor. I originally intended to make the language simpler to make it more accessible, but I eventually decided complexity was worth its price. For example, the language was originally designed to compile to javascript and only supported 64-bit floats and utf-16 strings, but things are a little different today. I accepted more complexity because It led to a more coherent and useful language and because I think AI makes greater levels of complexity tractable for users. In particular, I think most SakaQL interactions will be via an AI agent, and I think this because none of the software engineers I know hand-write code anymore.

Regarding the boil-the-ocean problem, it is very real and something I've tried not to succumb to, with some but not total success. The language has grown beyond the scope I originally envisioned. But I think there are two factors that help mitigate the problem.

First, AI tools unlock incredible productivity from small teams. It's much easier to boil the ocean than is used to be. Second, I decided early on that I wouldn't build a real transactional database because that's too much work and too hard to get right. That's why today's engine operates fully in memory and dumps to text files. It's a much easier problem to solve and much less disastrous when things go wrong.

The vision I'm trying to sell of SakaQL today is that its a really cool language with innovative ideas and not that its immediately practical. I am hoping that some of the people who are interested will check in again when I release the data tools built around SakaQL. That's when I think it will unlock real value.

1

u/GarageFullStack 1d ago

The bag semantics with unbounded integers and interval subtypes are interesting, but I'm skeptical about the performance overhead of native incremental view maintenance at scale without a dedicated storage engine. DBSP is cool in theory for changelog propagation, yet implementing it in a general-purpose language often means paying that cost in memory churn. You get nice syntax for parsing and types, sure, but you still have to wrestle with the underlying data structures when the dataset grows beyond what fits in RAM.

I looked at similar approaches where people try to keep everything in plain text files or git repos for portability. It works fine for micro-caps projects or small datasets where I can afford the latency, but it falls apart when you need real-time joins on millions of rows. The language design is solid for the garage dev workflow, but don't expect it to outperform a compiled Go service hitting an optimized index.

2

u/eejdoowad 1d ago

It all just works – as long as it fits in memory, which it won't always. This is the biggest theoretical blocker to making the language useful for general purpose programming. I haven't tried to solve it. Instead, my current implementation imposes strict memory limits and errors when they are exceeded. This is sufficient for my current target use case: human-curated, spreadsheet-scale data processing.

I also agree you're unlikely to see performance competitive with incumbent languages, particularly performance-tuned languages like Go, any time soon. But in theory, someone could optimize the language's implementation to the level of duckdb or clickhouse. And in practice, many applications are not performance sensitive, hence the use of languages like python and ruby.

3

u/MeMahi 11d ago

Interesting.

-14

u/commenterzero 11d ago

Gross

10

u/eejdoowad 11d ago

Why? Tell me more

-20

u/cheesekun 11d ago

If you don't know why it's gross then carry on inside your bubble.

-13

u/cheesekun 11d ago

This is not the problem to be solving right now in computer science. Whats the expression "tone deaf".