# Be Careful With CTE in PostgreSQL

DevFeed: [Be Careful With CTE in PostgreSQL](<https://devfeed.tech/articles/be-careful-with-cte-in-postgresql-33890.md>)

Original publisher: [Read original article](<https://hakibenita.com/be-careful-with-cte-in-postgre-sql>)

Author: Haki Benita

Published: 2018-09-16T21:00:00Z

Content type: tutorial

Language: en

Sources: [Haki Benita](<https://devfeed.tech/sources/haki-benita.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [cache](<https://devfeed.tech/tags/cache.md>), [cte](<https://devfeed.tech/tags/cte.md>), [index](<https://devfeed.tech/tags/index.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>), [sql](<https://devfeed.tech/tags/sql.md>)

## AI overview

This tutorial explains how Common Table Expressions (CTEs) can hurt query performance in PostgreSQL versions 11 and earlier. It compares a direct query with a CTE, showing that CTE materialization can prevent predicate pushdown and index use, and discusses subqueries as an alternative. PostgreSQL 12 changed its treatment of CTEs to address these issues.

## Source excerpt

Common table expressions, also known as the WITH clause, are a very useful feature. They help break down big queries into smaller pieces which makes it easier to read and understand. But, when used incorrectly they can cause a significant performance hit.