Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You could theoretically use Datalog anywhere you're currently using a SELECT SQL statement - it's a declarative way to produce a set of tuples given some existing sets of tuples.

But, Datalog is much better at deductive reasoning compared to SQL. There's a great interactive tutorial here: https://percival.ink/. To see how Datalog and SQL can be equivalent, I have a build of percival.ink that transforms simpler queries to SQLite: https://percival.jake.tl/

You can also see how Souffle itself can be useful in this blog post: https://ianthehenry.com/posts/drinking-with-datalog/

That post describes building a recipe engine that can tell you, given a bunch of recipes + the current contents of your bar cart, what drinks you can make, as well as giving you top ingredients you could buy that would allow you to make new drinks. It's quite a readable walkthrough of a very practical application of Datalog/Souffle in a place where SQL would certainly struggle.



I'm curious I can't find any reference to "unification" in percival's source code [1]. I'd assume you can't have datalog without unification :-)

1: https://github.com/ekzhang/percival


I've also worked on percival a bit, it compiles (transpiles?) the datalog ast into javascript code on demand and executes it to get the results, see [1]. Percival's creator, Eric, submitted a Show HN that received a couple comments [3], and also submitted a 10m presentation about the project to the HYTRADBOI 'virtual conference' earlier this year [2]. The Have You Tried Rubbing A Database On It conference included several awesome presentations featuring datalog, which readers may find interesting [4].

[1]: https://github.com/ekzhang/percival/blob/main/crates/perciva...

[2]: https://www.hytradboi.com/2022/percival-a-reactive-language-...

[3]: https://news.ycombinator.com/item?id=29521975

[4]: https://www.hytradboi.com/


Depending on what you mean, I'd say datalog is partially characterized as compared to prolog by it's lack of unification (also it's typically executed bottom up and sometimes considered to not have compound terms). Unification is roughly bidirectional pattern matching whereas datalog rules are in essence performing unidirectional pattern matching / query on a database.


You can do "deductive" reasoning in SQL too, via views and possibly-recursive CTE's.


Sure; you can do most Datalog things in SQL and most SQL things in Datalog. But I find it much clearer to express deductive reasoning in Datalog. I built a toy Datalog-to-CTE compiler at https://perceval.jake.tl if you want to play with some examples of the equivalence.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: