from Hacker News

Prolog language for PostgreSQL proof of concept

by triska on 3/30/24, 9:36 AM with 77 comments

  • by mark_l_watson on 3/30/24, 12:51 PM

    As a proof of concept, this looks very cool. Suggestion: add a short example to the README.

    I had one experience with Prolog in the 1980s that blew my mind. I had an IR&D project to build a complete prototype of an air/land battle simulator (yes, I was a defense contractor back then) in Common Lisp given 6 weeks of coverage to write it and demo it. After a month I was satisfied with the functionality and after demoing it I asked permission to rewrite it in ExperProlog on the Mac (I had done the Common Lisp version in my Xerox 1108 Lisp Machine). In ten days time it was done, and also had nice graphics and UI extensions that the Common Lisp version did not have. Anyway, except for few small open source things, that was the only large project I ever did in Prolog.

  • by steinuil on 3/30/24, 10:59 AM

    If you're interested in this I would also recommend you check out Logica[0], which is a datalog-like language that is explicitly made to compile to SQL queries.

    0: https://logica.dev/

  • by larodi on 3/30/24, 12:25 PM

    Love this, I've long considered that this should've been made as Prolog and SQL are ternary logic and basically SQL derives from Datalog and it itself from Prolog. A table record can be taught as of as a Prolog fact, so this makes the WHERE clauses the predicates in the conjunction on the right-hand side of a rule. And then exhausting the goal is actually returning the result-set.

    Hope to see this develop even further, as Prolog has its place with relational databases.

  • by joeatwork on 3/30/24, 10:41 AM

    An alternative query language for PostgreSQL would be a wonderful thing! But it isn’t clear that’s what this is.
  • by AceJohnny2 on 3/30/24, 7:21 PM

    Tangentially, Gerrit (a git Code Review web-app) deprecated the use of Prolog for the Submission Requirement feature.

    https://gerrit-review.googlesource.com/Documentation/prolog-...

    Prolog was introduced in 2.2.2 (2012), and deprecated in 3.6 (2022)

  • by p4bl0 on 3/30/24, 10:37 AM

    I would have liked actual examples of what it can do. With a simple table, and a few requests and their outputs.
  • by madsbuch on 3/30/24, 1:42 PM

    When I saw the title I hopes this would be schema aware. Looking into the current proof of concept they allow to write prolog definitions.

    How cool would be be, if all relations in a Postgres database would be lifted into the scope of a prolog process to work directly on the relations.

  • by west0n on 3/30/24, 3:45 PM

    Recently, I learned that PostgreSQL can integrate with many languages through plugins, such as PL/Python, pgrx (Rust), pgzx (Zig), and so on. I wonder if anyone is planning to write one for Java or C#, lol.
  • by ekoontz on 3/30/24, 2:42 PM

    I did some something like this a while ago:

    https://github.com/ekoontz/psqlog

  • by ainar-g on 3/30/24, 10:34 AM

    On a related note, have there ever been extensions for PosgreSQL/SQLite/any other FOSS DBMS that would allow using Tutorial D[1] (the Third-Manifesto one, not to be confused with Walter Bright's D language) to define and query data? In particular, I feel like PostgreSQL's CREATE TYPE[2] feature would allow for easier bridging between SQL and Tutorial D.

    Unfortunately, searches for “PostgreSQL Tutorial D” don't issue useful results for obvious reasons.

    [1]: https://www.dcs.warwick.ac.uk/~hugh/TTM/index.html

    [2]: https://www.postgresql.org/docs/current/sql-createtype.html

  • by nextaccountic on 3/30/24, 10:26 AM

    So, I expected this to actually query the DB using prolog (using the correspondence between relational algebra and logic programming).

    I mean, can those prolog stored procedures use the db as a source of facts for prolog, or otherwise write queries?

  • by ilaksh on 3/30/24, 12:38 PM

    Postgres is not just a relational db. It's a way of life.

    JSONB, HSTORE, LTREE, Full Text Search, Logical Replication, Range Types, BRIN Indexes, GIN Indexes, GiST Indexes, SP-GiST Indexes, Table Inheritance, Foreign Data Wrappers, XML Support, UUID-OSSP, pg_trgm, Cube, Earthdistance, pg_prolog, pg_partman, pgvector, TimescaleDB, PostGIS, Citus, pg_cron, BDR (Bi-Directional Replication), PL/Python, PL/Java, PL/V8, pg_stat_statements, pg_prewarm, pg_hint_plan, pg_repack, pgAudit, pgRouting, Multicorn (FDW), HypoPG, pg_squeeze, pglogical, Postgres-XL, Wal2json