News for hackers. Stuff that matters.
Re:Mindset Shifts for Functional Programming by dangwhy on Wednesday April 05, 2023 @10:02AM (#35454397)
> Nobody has yet convinced me that recursion has any sustained advantage over looping.

most sql systems support recursive queries. I believe recursive code can be analyzed by the system and executed in a the most efficient manner.

Loops have sideffects closely linking them to actual execution, which makes them blackboxes to the system.

Re:Mindset Shifts for Functional Programming by twic on Wednesday April 05, 2023 @11:04AM (#35455429)
If you're talking about recursive common table expressions, those are called recursive, but are really iterative. The PostgreSQL documentation describes the iterative evaluation:

https://www.postgresql.org/docs/current/queries-with.html#id...

Note how there is no way to remove a row from the result set once it has been added. That would not be the case with a truly recursive query, because you would be constructing a new result set at every step. As a concrete example, try to write a graph query which finds all nodes exactly three edges from some starting node. That would be trivial with true recursion, but is impossible with a recursive CTE alone.