Recursive 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.
Are 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 ;)
Yeah 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.
It'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...
7 comments
[ 1.7 ms ] story [ 42.6 ms ] thread