我正在处理从外部源收到的 JSON 文档。在本文档中,有一个timestamp属性对应于timestampPostgreSQL 数据类型的文本格式。换句话说,它可以被转换为timestamp类型:(data->>'timestamp')::timestamp。
我想timestamp在索引中使用该属性。我尝试了以下方法:
create table t
(
data jsonb
);
create index on t(((data->>'timestamp')::timestamp));
Run Code Online (Sandbox Code Playgroud)
我正进入(状态:
ERROR: functions in index expression must be marked IMMUTABLE
Run Code Online (Sandbox Code Playgroud)
为什么是这样?我知道转换为 atimestamptz并不是不可变的,因为本地化配置设置不是静态的,但我无法将该逻辑应用于转换为timestamp.
还有办法将我的timestamp财产放入索引吗?
我正在使用几天前发布的 PostgreSQL 12。