I have a PostgreSQL database of users and their birthdays and want to get all users in a specific age range:
SELECT * FROM users WHERE age(birthday) >= 21 AND age(birthday) <= 30;
How can I achieve that this query stays efficient, even when there are millions of users in the database?
Of course there are more filters, I just don't want to calculate the age for every row.
I do not want to use a materialized view.