Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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 ...


neat trick!

sometimes you absolutely need to materialize your CTE, especially if it is one big computation and you refer it 4-5 times downstream.


According 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: