1

I have a table partitioned by year. With this query :

select *
from myTable
where year between '2018' and '2020'

the query plan is good, only 2018,2019,2020 partitions are used.

But with this query

select *
from myTable
where year between '2018' and extract(year from now())::text

the partitions 2021 and 2022 appears in the query plan, why ?

0

1 Answer 1

1

In PostgreSQL v10, partition pruning (removal of unneeded partitions) can only happen at query planning time, but at that time the value of extract(year from now())::text is not known.

If you use PostgreSQL v11 or later, your query should perform as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.