snthpy 3 years ago

TL;DR: PRQL recently added a `loop` construct which makes it Turing Complete and allows doing cool things like calculating Pi right in your database.

Last week saw the 0.6 release of PRQL which brought with it the capability to express Recursive CTEs in PRQL. "Recursive" CTEs aren't actually truly recursive in the sense that that term is usually used, rather they use a "recursive" (i.e. self-referential) syntax to provide a looping construct in SQL.

PRQL is a modern, functional query language for transforming data. One of its goals is to simplify working with data wherever you can currently use SQL. As such it compiles to SQL while making available modern ergonomics such as f-strings, as well as not so modern features such as functions.

Given that the underlying semantics of Recursive CTEs are really about iteration or "looping", we have called this feature loop in PRQL.

This post introduces the new `loop` feature in PRQL and shows how this can be used to calculate Pi right in your database!

Happy Pi Day everyone!