October 13, 2025
PG will not run CTEs unreferenced
Postgres will not run any CTEs not referenced in the main query. It’s a form of optimization in newer versions.
E.g.,
WITH will_not_run AS (SELECT 1/0), ok AS (SELECT 1)
SELECT * FROM ok;
October 13, 2025
Postgres will not run any CTEs not referenced in the main query. It’s a form of optimization in newer versions.
E.g.,
WITH will_not_run AS (SELECT 1/0), ok AS (SELECT 1)
SELECT * FROM ok;