Question: Given SQL's apparent Turing completeness, is it theoretically possible to build a compiler using SQL?
Answer: Yes, SQL is indeed Turing complete even without external extensions like PL/SQL or PSM.
Proof: Andrew Gierth proved in a demonstration that SQL is Turing complete without script extensions. By implementing a cycle marking system (a proven Turing-complete model), he demonstrated that SQL can solve problems recursively. In this context, the key feature is CTE (Common Table Expression), which allows self-referential subexpressions.
Meaning:
The discovery of SQL’s Turing completeness highlights the scalability of this primarily declarative query language. Just as C's templates unexpectedly became Turing-complete, SQL's CTE properties make it a more general language.
Example:
A notable example is the creation of the Mandelbrot Set in SQL, demonstrating the potential of the language in computationally intensive applications.
The above is the detailed content of Can SQL, Without Extensions, Achieve Turing Completeness?. For more information, please follow other related articles on the PHP Chinese website!