# How to Achieve Pruning When Querying by Non-Partitioned Columns in PostgreSQL

DevFeed: [How to Achieve Pruning When Querying by Non-Partitioned Columns in PostgreSQL](<https://devfeed.tech/articles/how-to-achieve-pruning-when-querying-by-non-partitioned-columns-in-postgresql-33924.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-partition-pruning>)

Author: Haki Benita

Published: 2026-07-08T21: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>), [Databases](<https://devfeed.tech/topics/databases.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [index](<https://devfeed.tech/tags/index.md>), [partition](<https://devfeed.tech/tags/partition.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>)

## AI overview

This tutorial explains PostgreSQL partition pruning and shows how certain data patterns can enable pruning when queries filter on columns other than the partition key. It uses event data partitioned by year and examines queries by date range and session.

## Source excerpt

Under conventional wisdom, pruning can only be achieved when querying by the partition key. However, if your data follows certain patterns, using some clever tricks you can achieve pruning even when filtering by non-partition key columns.