3 ms·
Using common table expressions to solve the “eight queens” problem in SQL
- zrail 12y agoRecursive CTEs are super cool! I don't use them very often for the problems I'm trying to solve, but I regularly use non-recursive CTEs to organize queries instead of using deeply nested subqueries.
- peri 12y agoI hope you warn your dbas before you do this :)
- zrail 12y agoAre you referring to the fact that CTEs are an optimization boundary in PostgreSQL and (presumably) most other systems? In any case, most of the time I'm the DBA so it doesn't really matter ;)
- peri 12y agoSorry to poke this thread so far later, but I was actually thinking more of other users of your VMs if you're doing this in the cloud :)
- ThePhysicist 12y agoYeah I agree, most queries can be done without using CTEs, but some problems can hardly be solved without them. I'm thinking e.g. of finding paths in a graph or querying highly hierarchical data in an efficient way.
- monokrome 12y agoIt's worth noting here that the comment suggesting "--note the 'RECURSIVE' keyword, which states that we want to define a CTE" isn't exactly correct. This is a recursive CTE, but the RECURSIVE isn't required for it to still be a CTE...
- ThePhysicist 12y agoGood point, I'll change it in the text!