小编bas*_*ser的帖子

为什么无法转换为 PostgreSQL 索引中的时间戳?

我正在处理从外部源收到的 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。

postgresql index timestamp cast postgresql-12

5
推荐指数
1
解决办法
5484
查看次数

标签 统计

cast ×1

index ×1

postgresql ×1

postgresql-12 ×1

timestamp ×1