4 ms·
> CTEs aren't materialized so they're not tables. You might well know this, but one thing thats worth pointing out is that in Postgres you _can_ materialise th
by aidos 3y ago
> CTEs aren't materialized so they're not tables.
You might well know this, but one thing thats worth pointing out is that in Postgres you _can_ materialise the CTEs (though it's more to trick the planner when your use case is more about making sure everything to exploded and indexed in advance).
with x as materialized (select ..) select ...
- deleted 3y ago[deleted]
- slt2021 3y agoneat trick! sometimes you absolutely need to materialize your CTE, especially if it is one big computation and you refer it 4-5 times downstream.
- mulmen 3y agoAccording to the docs [1] this is not necessary: > All queries in the WITH list are computed. These effectively serve as temporary tables that can be referenced in the FROM list. A WITH query that is referenced more than once in FROM is computed only once, unless specified otherwise with NOT MATERIALIZED. [1]: https://www.postgresql.org/docs/15/sql-select.html https://www.postgresql.org/docs/15/sql-select.html
- deleted 3y ago[deleted]