3 ms·
> While SQL isn't normally used as a general purpose programming language I think it's quite illustrative for those otherwise unfamiliar with declarative langua
by andsoitis 2y ago
> While SQL isn't normally used as a general purpose programming language I think it's quite illustrative for those otherwise unfamiliar with declarative languages (though apparently it is Turing complete)
SQL itself is not Turing complete in its standard form because it lacks some essential features of a Turing machine, such as the ability to simulate unbounded loops or recursion within a single query.
SQL with procedural extensions, such as PL/SQL (Oracle), T-SQL (Microsoft), and PL/pgSQL (PostgreSQL), are Turing complete because they allow constructs such as loops, conditionals, and recursive functions.
- GregDavidson 2y agoSQL with CTEs is also Turing complete, which is not necessarily ideal. The Rule of Least Power https://en.m.wikipedia.org/wiki/Rule_of_least_power https://en.m.wikipedia.org/wiki/Rule_of_least_power suggests avoiding OP languages. Less powerful languages can be more transparent (great for expressing contracts, e.g. specifications), tractability (proofs, optimization, termination, etc.) and so on. Many systems have been ruined by making them Turing complete.
- qu1j0t3 2y agoI'd upvote this twice if I could. It is a great strength of the popular subset of SQL that it is _not_ Turing complete.
- 29athrowaway 2y agoUsing SQL is perfectly fine. Datalog on the other hand is absurdly hard to work with.
- guskel 2y agoTo each their own. Others would say datalog elegant and makes it easy to compose statements whereas SQL has an ugly syntax. I mean, ORMs were invented to try to avoid writing SQL but they too have their own problems.
- sgarland 2y ago> SQL has an ugly syntax Speak for yourself. I’ve always found it to be very clear and concise. SELECT <tuples> FROM <table> [[type of] JOIN other_table ON ?, …] [WHERE ? [boolean operator], …] [ORDER BY ? [DESC]] [LIMIT ?]
- baq 2y agoAnsi SQL 99 defines recursive ctes. https://en.m.wikipedia.org/wiki/SQL:1999 https://en.m.wikipedia.org/wiki/SQL:1999