我正在尝试创建以下索引

问题描述 投票:1回答:1
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
postgresql indexing postgresql-9.5
1个回答
0
投票

[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'))
);

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

© www.soinside.com 2019 - 2024. All rights reserved.