Live data from Hacker News

Prolog language for PostgreSQL proof of concept

github.com

11–20 of 83 posts

Re: Prolog language for PostgreSQL proof of concept

#11

An alternative query language for PostgreSQL would be a wonderful thing! But it isn’t clear that’s what this is.

yes, I have plans to try adding some query helpers eventually.

One could imagine representing queries as compound terms, like: q(user(id=Id, name=like("Bob%"), email=Email))

which would query, from user table and bind Id and Email for all matches. I plan to experiment with something like that.

Re: Prolog language for PostgreSQL proof of concept

#12

An alternative query language for PostgreSQL would be a wonderful thing! But it isn’t clear that’s what this is.

> it isn't clear that's what this is

Because that's not what this is - this is for when you write e.g. `language plpgsql` in defining some function; instead of that (with this installed) you could write `language plprolog` and use prolog.

Re: Prolog language for PostgreSQL proof of concept

#13

An alternative query language for PostgreSQL would be a wonderful thing! But it isn’t clear that’s what this is.

If you're interested in an alternative query language, https://prql-lang.org/ is a good one.

Thanks for the mention. For Postgres, the easiest way to use PRQL is the plprql extension:

Link: https://github.com/kaspermarstal/plprql

Previous discussion: https://news.ycombinator.com/item?id=39428609

Re: Prolog language for PostgreSQL proof of concept

#14
post #3

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…

You might enjoy https://www.cidrdb.org/cidr2024/papers/p48-neumann.pdf and https://github.com/viktorleis/saneqlcpp

Re: Prolog language for PostgreSQL proof of concept

#15
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.

Re: Prolog language for PostgreSQL proof of concept

#16
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

Re: Prolog language for PostgreSQL proof of concept

#17
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.

Re: Prolog language for PostgreSQL proof of concept

#19
post #18
post #7

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/

Oh nice, this is the one "SQL replacement" I'd actually look into

What puts you off prequel? https://prql-lang.org

really readable, nice syntax imo

Re: Prolog language for PostgreSQL proof of concept

#20

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 demoin…

Can you explain a little about why / how you modeled a battle simulation in Prolog?

To me, the most natural approach is simply a time-stepped battlespace model. With event uncertainty (e.g., did the bullet hit its target?) modeled as random draws that get baked into the outcome.

Post reply on HN