Common Table Expression (CTE)
A way of writing subqueries for use in a larger SELECT query.
A Common Table Expression
(CTE
) is a way of writing subqueries for use in a larger SELECT query, using a WITH
clause.
Support for Common Table Expressions
was added in PostgreSQL 8.4.
Change history
- PostgreSQL 12
MATERIALIZED
/NOT MATERIALIZED
clauses for controlling materialization (commit 608b167f) added
- PostgreSQL 8.4
- added (commit 44d5be0e)
References
- PostgreSQL documentation: WITH Queries (Common Table Expressions)
Useful links
- Using CTEs to do a binary search of large tables with non-indexed correlated data - October 2020 blog by David Christensen / End Point