Postgres not using index when expression in WHERE condition
The plan is determined before the query is executed, and such a choice cannot be made at execution time in PostgreSQL.

I see two ways:


execute two queries and use the result of the first in the second
add a second "cut off" condition like

AND t.timestamp &gt; '2020-01-01'


that won't change the result, but let the optimizer know that an index scan will be the right choice