首页 > 解决方案 > jsonb文本搜索索引

问题描述

我将地址数据拆分为 JSONB 列中的字段

我想对这些数据进行自由文本搜索,并注意到 postgres 11 具有函数 jsonb_to_tsvector()

我正在尝试在我的表上创建一个索引: -

CREATE INDEX ad_jsonb_ts_vector
ON my_address_data
USING GIN (jsonb_to_tsvector('English'::regconfig, address_data::JSONB, jsonb_build_array('text', 'numeric')));

这给了我错误:-

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

但据我了解,这种形式的 jsonb_to_tsvector 是不可变的吗?

select provolatile from pg_proc 
where proname = 'jsonb_to_tsvector' 
AND oid::regprocedure ='jsonb_to_tsvector(regconfig,jsonb,jsonb)'::regprocedure

返回“我”。

我错过了什么还是这是一个 postgres 错误。版本是 11.5

标签: postgresqlindexingjsonb

解决方案


函数 jsonb_build_array 是稳定的,不是一成不变的。试试这个:

CREATE INDEX ad_jsonb_ts_vector
ON my_address_data
USING GIN (jsonb_to_tsvector('English'::regconfig, address_data::JSONB, '["text", "numeric"]'::jsonb));

推荐阅读