8 ms·
Prolog language for PostgreSQL proof of concept
- nextaccountic 3y agoSo, 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?
- ainar-g 3y agoOn 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 https://www.dcs.warwick.ac.uk/~hugh/TTM/index.html [2]: https://www.postgresql.org/docs/current/sql-createtype.html https://www.postgresql.org/docs/current/sql-createtype.html
- justinclift 3y agoMaybe ask on a suitable sounding PostgreSQL mailing list? * https://www.postgresql.org/list/ https://www.postgresql.org/list/ The catch-all "general" one is probably good enough if nothing else seems like a closer match. :)
- cmrdporcupine 3y agoYou might enjoy https://www.cidrdb.org/cidr2024/papers/p48-neumann.pdf https://www.cidrdb.org/cidr2024/papers/p48-neumann.pdf and https://github.com/viktorleis/saneqlcpp https://github.com/viktorleis/saneqlcpp
- p4bl0 3y agoI would have liked actual examples of what it can do. With a simple table, and a few requests and their outputs.
- tatut 3y agothat is coming, once I get it a bit more developed... this isn't anywhere near usable for real yet
- joeatwork 3y agoAn alternative query language for PostgreSQL would be a wonderful thing! But it isn’t clear that’s what this is.
- mritchie712 3y agoIf you're interested in an alternative query language, https://prql-lang.org/ https://prql-lang.org/ is a good one.
- snthpy 3y agoThanks for the mention. For Postgres, the easiest way to use PRQL is the plprql extension: Link: https://github.com/kaspermarstal/plprql https://github.com/kaspermarstal/plprql Previous discussion: https://news.ycombinator.com/item?id=39428609 https://news.ycombinator.com/item?id=39428609
- tatut 3y agoyes, 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.
- OJFord 3y ago> 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.
- steinuil 3y agoIf 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/ https://logica.dev/
- zilti 3y agoOh nice, this is the one "SQL replacement" I'd actually look into
- breakfastduck 3y agoWhat puts you off prequel? https://prql-lang.org https://prql-lang.org really readable, nice syntax imo
- otabdeveloper4 3y ago"Unreadable syntax" is like number 1000 on the list of SQL problems.
- hashmash 3y agoPRQL has some very nice features, but the syntax also has some not so nice features that you don't see in the examples. There's special parsing rules for parenthesis and newlines, and a special word wrap character is needed at times to disable the rule that treats newlines as the pipe operator.
- ryanjshaw 3y agoI was wondering how this was possible and then found this monstrosity: https://colab.research.google.com/github/EvgSkv/logica/blob/main/examples/Logica_example_Reachability.ipynb https://colab.research.google.com/github/EvgSkv/logica/blob/... Click on the SQL tab.
- cess11 3y agoSeen longer, more obtuse queries written by hand in some applications I've worked on. Big, useful systems often give rise to them eventually.
- larodi 3y agoLove 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.
- Edidiongben9 3y ago[flagged]
- kevindamm 3y agoProlog's evaluation semantics are order-dependent, though. I've always thought this was the reason why the two language paradigms didn't see more merging than they did. There are some datalog+RDBMS hybrids but, as much as I'm not a fan of .NET, I think LINQ has seen the most success in this space.
- neonsunset 3y agoWhat are you concerned about when using .NET?
- tejtm 3y agotheir soul?
- kevindamm 3y agoFor me, I just haven't enjoyed the developer experience. It's been a few years so take my opinions with a dash of salt but I find the language itself verbose, I should be freed of having to think about its memory layout because of garbage collection but I still end up thinking about it because of type boxing and enumerator-wrappers, the garbage collection routine itself is not as mature as other environments that I'm familiar with (perhaps that has improved?)... and, I know some of my characterization is unfair. Among the .NET/CLR languages I really only have in-depth experience with C# and perhaps I should give one of the others a chance. I also carry baggage from a few years on a Unity project that twists what C# actually is (like how async/await is mangled and the way some library routines are only available from the main thread). I also probably allow my experience on a Java project (a few years of rather high stress) to bias me w.r.t. C# but I know that's also unfair, but these make me less likely to approach the language. It wouldn't be a deal-breaker for me to join a team but it would step down my enthusiasm some. I will say, though, that the .NET authors did seem to learn some lessons from Java's worse API decisions and the .NET API is more uniform and reasonable overall.
- ilaksh 3y agoPostgres 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
- pjmlp 3y agoAll enterprise level RDMS have similar capabilities, some of which are yet to come to Postgres.
- qweqwe14 3y agoPostgres is currently the most advanced RDMS, anyone who's not locked in by Oracle or whatever and doesn't use Postgres for new projects is likely misinformed. Postgres essentially made every other RDMS obsolete except for some niche circumstantial cases (e.g. vendor lock-in) > enterprise level Postgres is enterprise level (whatever that means). Blazingly fast, Web 3, cloud-native, etc etc, pick your own buzzwords
- pjmlp 3y agoThe same applies to those that think Postgres does everything, every single feature, that Oracle, SQL Server, DB 2, and co, are able to deliver, in projects where their license costs are kind of irrelevant in the big context of the organization. Usually, it is a great way for many organizations to have a database as free beer.
- qweqwe14 3y agoSure, a few organizations may actually need some obscure feature that Oracle provides, but again, it's niche. For most companies, Postgres provides way more features than they will ever use. And for the other 1%, it sometimes happens that their need for a specific feature in Oracle DB turns out to be entirely unnecessary. Not to mention that the vast majority of products turn out to be fancy CRUD apps. Doesn't matter though, Oracle will convince you that you NEED their DB regardless.
- mark_l_watson 3y agoAs 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.
- CoastalCoder 3y agoCan 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.
- mark_l_watson 3y agoHonestly, that was almost 40 years ago and the details escape me. I do remember that it was not a fine detail model. I think some ‘experts’ in my company wrote up how they solved certain problems and I tried to capture that. I might have used OPS5 in the Common Lisp prototype. I (in hindsight) wasted a lot of time back then on symbolic AI that didn’t scale, and not enough time with neural networks. I was on a DARPA neural network advisory panel in the mid 1980s and I had a few good wins using NNs.
- crq-yml 3y agoMy speculative reaction: Prolog offers a way to describe an AI "commander" that can make plans that optimize for many units simultaneously. This technique is often used in strategy games, not usually with Prolog itself but using similar hand-written planner algorithms in tandem with FSMs. One of the downsides of this approach where it appears in games is that it results in unit behaviors that look robotic and overly micromanaged, often using tactics similar to early computer chess AI.
- madsbuch 3y agoWhen 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.
- kevindamm 3y agoIf your entire database can be lifted into the application's heap, it's probably small enough that I wonder why you've got it stored in an RDBMS... and because Prolog is lexically sensitive (order of sentences and the order of clauses in the sentence affect the eval result) then you would need to effectively load all related DB entries -- or maybe some cursor tricks to load domain entries lazily and the many small queries that entails. What I've usually seen instead is starting from Datalog (declarative, order-independent) instead of Prolog, and converting that into the relevant SQL queries then loading the results into variables within the datalog context. This splits the knowledge base into IDB and EDB parts.
- naasking 3y ago> If your entire database can be lifted into the application's heap, it's probably small enough that I wonder why you've got it stored in an RDBMS I think he meant lifting the database schema, not the whole database. This would help with auto completion and other static checks before trying to run queries.
- Izkata 3y agoMuch much more important would be the foreign keys. If I remember my prolog correctly, this: parent(alice,bob). is duplicating information that could already be found in the schema's relationships.
- madsbuch 3y agoSomething like this! So that you can naturally query your data defining relationships and constraints (This can already be done using joins, but that is not very ergonomical, especially when a lot of relations are at play)
- Edidiongben9 3y ago[flagged]
- victorbjorklund 3y agoHaha what kind of weird spam is this?
- dr_kiszonka 3y agoLooks like it is Bitcoin-related.
- ekoontz 3y agoI did some something like this a while ago: https://github.com/ekoontz/psqlog https://github.com/ekoontz/psqlog
- west0n 3y agoRecently, 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.
- neonsunset 3y agoNot that I'm aware of but any plugin system that expects dynamically linked binaries integrating through C API can be targeted by .NET NativeAOT (e.g. OBS plugins can be written in C# without manually dealing with hosting the runtime).
- fiddlerwoaroof 3y agoThere has been PL/Java for a long time: https://tada.github.io/pljava/ https://tada.github.io/pljava/ and PL/Perl and others. The projects you mention are largely building on well-established interfaces in Postgres.
- AceJohnny2 3y agoTangentially, Gerrit (a git Code Review web-app) deprecated the use of Prolog for the Submission Requirement feature. https://gerrit-review.googlesource.com/Documentation/prolog-cookbook.html https://gerrit-review.googlesource.com/Documentation/prolog-... Prolog was introduced in 2.2.2 (2012), and deprecated in 3.6 (2022)
- deleted 3y ago[deleted]