It seems that writing Declarative
SQL is very popular in Imperative Programming. However, it also seems that writing Declarative
Prolog could save a lot of complexity but this is not very common.
Is there a historical precedent for this apparent preference of SQL over Prolog?
If the reason is lack of native support by Imperative languages, then is it possible to answer why the language creators didn't find it useful to natively support
Prolog in the first place?
To provide some specific examples:
Evaluating a loan application might be just a few lines of code in
Prolog, like the
SELECT/JOIN query that is just a few lines of code in
SQL, but it seems the advantage is not as obvious as
Here is another example problem and the solution in Prolog. The following constraint logic program represents a simplified dataset of john's history as a teacher:
teaches(john, hardware, T) :- 1990 ≤ T, T < 1999. teaches(john, software, T) :- 1999 ≤ T, T < 2005. teaches(john, logic, T) :- 2005 ≤ T, T ≤ 2012. rank(john, instructor, T) :- 1990 ≤ T, T < 2010. rank(john, professor, T) :- 2010 ≤ T, T < 2014.
The following goal clause queries the dataset to find out when john both taught logic and was a professor:
:- teaches(john, logic, T), rank(john, professor, T).
2010 ≤ T, T ≤ 2012.
In the above example it will be easy with
SQL to get the same result. But suppose that you have this data in an
Array. Then it is not as easy to get the same results using
SQL. And in the case of data stored in an array, I believe that the Prolog code will be easier to write and maintain.