alt.hn

7/13/2026 at 8:00:10 PM

Show HN: I implemented a neural network in SQL

https://github.com/xqlsystems/xarray-sql/blob/claude/xarray-sql-mnist-demo/benchmarks/nn.py

by alxmrs

7/14/2026 at 4:51:30 AM

I don't want to rain on discovering a genuinely cool bit of theory, but it's not "new" per se.

The equivalence with Einstein summation was noted in this paper [0]. Sandia labs wrote an SQL database based around graphBLAS called TenSQL a few years back. And something similar to your idea of relational algebra as the basis for AI had a paper published earlier this year [1], naming it Tensor Logic.

    Are all of these common operations secretly relational, just with the wrong data model?
Sadly not, but you can get a long way before you find the limits. Modern databases are very well optimized for their use cases, but there's many other possible points in the design space to explore. If you want to really make efficient use of hardware, there are fundamental scaling problems with natural joins because of the combinatorial explosion that gives us WCO though. If you accept an inability to express triangular queries, you can get something that's embarrassingly parallel and scales really flipping well.

If you want to stick to the full relational model, you might be interested in Differential Dataflow [2].

[0] https://arxiv.org/html/2510.12269v3

[1] https://arxiv.org/html/2601.17188v1

[2] https://github.com/TimelyDataflow/differential-dataflow

by AlotOfReading

7/15/2026 at 8:20:25 PM

Really happy to hear that this isn't new – with citations. I am a fan of rain :) Thank you for the references. I'm looking to build a real production system that could be used by scientists and data practitioners, grounded in a academic perspective. So, all this prior art is very helpful.

> Sadly not, but you can get a long way before you find the limits.

I'm really curious to know what the limits are! If you have a good understanding of these, I'd love to hear your perspective. I do think it's valuable to be able to spill out to the array paradigm, and that a project like Xarray-SQL lets users choose the best tool for the job.

I am a fan of Differential Dataflow, though I don't know the system too well. I'll take a closer look when I can.

by alxmrs

7/13/2026 at 10:50:13 PM

I've been working on something similar, implementing a relational language on top of a tensor library[0].

Mathematically, einsum and database joins are the same thing, just over different semirings (real numbers for einsum, booleans for databases). A lot of papers about datalog explore this sort of thing in more depth. In particular, Dyna[1] might be interesting.

[0]: https://arxiv.org/abs/2509.22614 [1]: https://dyna.org/

by sporkl

7/13/2026 at 9:02:34 PM

Somewhat more reliable than implementing SQL in neural networks.

by HPsquared

7/13/2026 at 11:33:01 PM

In the past platforms have integrated ML algorithms into relational databases and SQL through extensions (both commercial and open source). A famous open source one was MADlib [1], which has an implementation of neural networks. Even the commercial ones were similar, I used ML algorithms in SQL Server many years ago around 2005 I think.

I am wondering about.. SQL as a declarative structured query language that can be optimized into essentially any kind of distributed, directed acyclic graph of processing - vs the special characteristics of relational databases (relational algebra, relvars, etc. etc.) is an important distinction as - of yet, I see the author linking both together so I'm trying to understand what it is about relational structures that specifically helped here (just not seeing it yet, not that it isn't there).

Also, wondering if ISO/IEC 9075-15:2023 SQL standard for multidimensional arrays (MDA) is of any use here? Paper describing SQL/MDA here [2].

[1] https://madlib.apache.org/documentation.html

[2] https://www.ifis.uni-luebeck.de/~moeller/Lectures/WS-19-20/N...

by sixdimensional

7/13/2026 at 11:50:15 PM

I need to better understand your first question before I can comment. In theory, we could work with MADlib too -- what we do is port scientific data, which typically is a "tensor" or Nd array, into a tabular view. I believe you know relational theory better than I do, I am still fairly new to the field.

WRT ISO/IEC 9075-15:2023: This is the standard established from rasdaman, IIUC. I reject this approach (which treats arrays as a column type), and instead adopt one inspired by Michael Stonebraker's SciDB (which treats arrays as tables themselves). For an in depth review of the topic, I recommend this NSF paper: https://par.nsf.gov/servlets/purl/10545560

by alxmrs

7/14/2026 at 4:03:13 AM

I'll try it next time I've got Greece vacation money

by ReactiveJelly

7/14/2026 at 5:11:48 AM

It did seem cross-posted from LinkedIn

by harvey9

7/13/2026 at 10:03:11 PM

Neat! Feels analogous to "X runs Doom" demos (but NN).

by soupspaces

7/13/2026 at 10:43:34 PM

Just today I saw this implementation of DOOM in SQLite using a recursive CTE for a simple ray tracer: https://github.com/petergpt/doomql

by simonw

7/13/2026 at 8:41:36 PM

I'm just going to go back to making my CRUD endpoints...

Jokes aside, sounds really impressive, though I only understood about 10% :D

by tommica

7/14/2026 at 8:02:20 AM

Looks good, i will try today

by Sia123

7/13/2026 at 8:59:34 PM

initially rolled my eyes at "neural networks in SQL," but after reading the code I came away impressed

basically it comes down to using relational algebra as the IR, letting a database optimizer reason about tensor programs

by 0xnyn

7/13/2026 at 9:12:34 PM

I would have had the same gut reaction as you lol.

You’re spot on. I think that SQL, as a data oriented and logic PL, might be ideal for writing tensor programs.

by alxmrs

7/14/2026 at 1:55:25 AM

Fable is impressed.

by handfuloflight

7/14/2026 at 2:33:14 PM

Babymoon?

by NuclearPM

7/13/2026 at 8:36:38 PM

[dead]

by slipperybeluga

7/13/2026 at 10:04:10 PM

[dead]

by throwaway613746