4 ms·
> In SQL, on the other hand, you'd have to write each of these queries by hand Nope. Can be written as a non-predicated recursive CTE. Just add a 'where' at th
by _a_a_a_ 3y ago
> In SQL, on the other hand, you'd have to write each of these queries by hand
Nope. Can be written as a non-predicated recursive CTE. Just add a 'where' at the end to specify what you want.
The practical difference is in the way the search takes place. In SQL you would get the right results but it might take a lot longer because it might (depending on what you're looking for) generate all possibilities and just pick the ones you want. In Prolog I think it's a bit more intelligent in searching.
That depends, of course because it's an implementation detail and predicate pushdown or whatever might regain that efficiency, but from experience I can say It Depends.
(I recently did something like this at work, so it is actually useful)
Edit: see https://www.andrewvillazon.com/recursive-cte-sql-server/ https://www.andrewvillazon.com/recursive-cte-sql-server/ for something similar