AdvancedAdvanced PostgreSQL

Theory: What are CTEs?

The query

SQL
-- Q: What is a Common Table Expression (CTE)?
-- A: A temporary result set defined using the WITH clause. 
-- It exists only during the execution of a single query.
-- PostgreSQL allows CTEs to be Recursive (for traversing trees/graphs) 
-- and Writable (Data Modifying CTEs with INSERT/UPDATE/DELETE RETURNING).
Tested against PostgreSQL 16

Note

PostgreSQL 12+ optimizes CTEs by inlining them unless specified WITH MATERIALIZED.