我正在尝试创建以下索引

I'm trying to create the following index

CREATE INDEX request_response_partition_idx
  ON public.request_response_partition USING btree (userid,extract('Month' from time_stamp));

我收到错误;

ERROR:  functions in index expression must be marked IMMUTABLE

********** Error **********
ERROR: functions in index expression must be marked IMMUTABLE
SQL state: 42P17

time_stamp 必须是 timestamp with time zone.

您必须在适当的时区将表达式 IMMUTABLE 转换为 timestamp without time zone

CREATE INDEX request_response_partition_idx
ON public.request_response_partition (
   userid,
   extract('Month' FROM (time_stamp AT TIME ZONE 'UTC'))
);

当然,您还必须修改查询中的表达式以匹配索引。