This is an external article made in collaboration with another source. Click the button below to view the whole article.
Common Table Expressions (CTEs) are my go-to tool when writing complex SQL queries. They can be thought of as working like sub-queries or temporary tables but with their own superpowers.
In this article, we’ll take a deep dive into what CTEs are and how they can simplify your queries, how recursive CTES can turn impossible PostgreSQL queries into possible, and how to use CTEs to create optimization fences to improve the performance of your queries.
One of the Postgres posts on the site. The full track, grouped by topic, lives on the guide page .