Can SQL do resolution or backtracking similar to Prolog, I wonder.
A relation (table) in SQL is conceptually a predicate that holds for all tuples (rows) therein. You can AND the predicates with "NATURAL JOIN". You can OR them with "UNION"
e.g. this example https://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prologpa...
becomes something like this in SQL.
example=# select * from red;
item
---------
apple_1
block_1
car_27
(3 rows)
example=# select * from car;
item
-----------
desoto_48
edsel_57
(2 rows)
example=# select * from blue;
item
----------
flower_3
glass_9
honda_81
(3 rows)
example=# select * from bike;
item
----------
iris_8
my_bike
honda_81
(3 rows)
example=# CREATE view fun as (select item from red NATURAL JOIN car) UNION (select item from blue NATURAL JOIN bike);
CREATE VIEW
example=# SELECT * FROM fun;
item
----------
honda_81
(1 row)Prolog tutorials really do Prolog a disservice by introducing it as a database query language, which is then misunderstood (or misremembered) by many as "it's only a database query language".
example=# select * from move;
place | method | newplace
---------+--------+----------
home | taxi | halifax
halifax | train | gatwick
gatwick | plane | rome
(3 rows)
example=# create view on_route as with recursive on_route(place, newplace, length, path) as (select place, newplace, 1 as length, place as path FROM move UNION select on_route.place, move.newplace, on_route.length + 1, path || '->' || move.place as path FROM move JOIN on_route ON on_route.newplace = move.place) SELECT place, newplace, length, path || '->' || newplace as path FROM on_route;
CREATE VIEW
example=# select distinct true from on_route WHERE place = 'home' and newplace = 'rome';
bool
------
t
(1 row)
example=# select path from on_route WHERE place = 'home' and newplace = 'rome';
path
------------------------------
home->halifax->gatwick->rome(The greater point still stands, terms and unification and all that.)