Suppose I have defined a function that is expensive to compute. Is there a way to define an index in PostgreSQL to cache the return value for a given set of parameters?
For example, let's say that I have a function stats(year, month)
to calculate some statistics for the given year
and month
. Is there a way to precompute the result for the years 2019, 2020, 2021 using an index or any other technique?
create index on the_table ((stats(year, month)))