Is Prolog Better Suited Than SQL?Sep 26, 2005 · 2 minute read · Comments
I am currently reading a Prolog book “Artificial Intelligence Through Prolog”, I have been doing a bit of Prolog when I was very young and wanted to refresh my memory a bit. It is a very interesting read, especially when I take the viewpoint of our current application where no ACID compliance is required.
It seems to me that all the logic we coded to parametrize SQL queries and construct them dynamically could have been avoided if we had chosen Prolog as Prolog expressions would have been very natural to use in our project. With Prolog, there is no need to think about joins, type of joins, SQL syntax. It is at the level just higher. I wonder very much why Prolog did not become more mainstream as it seems to solve some problems in a much nicer, natural way.
Here is a short example to get reviews of things by user or by user and tags or …:
- let’s define some facts:
- is_tag(tag1, user1, thing_id)
- is_tag(tag2, user1, thing_id)
- review(user1, thing_id, description, extended, date)
- ?review(user_x, THING_ID, DESC, EXT, DATE)
- ?review(user_x, THING_ID, DESC, EXT, DATE), is_tag(tag_y, user_x, THING_ID)
Now of course, Prolog does not necessary makes sense for us because:
a) We already have it working in SQL
b) SQL is much more used and should therefore be more tunable, stable, etc.
Still the Prolog way of things is interesting and powerful. We could have written a code with a logic near Prolog instead of our custom code.
Tags: book review