在jsonb列postgresql9.5上创建gin索引时出错

问题描述 投票:1回答:1

我有product_reviews表与product_review jsonb列。

jsonb column : [{"comment": [{"condition": "Good", "Entered": "true"}], "productid": 321}]

CREATE INDEX idx_product_reviews_product_review ON product_reviews  USING gin (CAST (product_review ->> 'productid') AS bigint )   ;

所以当我尝试在这个jsonb列上创建gin索引时,我得到错误。

ERROR:  data type bigint has no default operator class for access method "gin"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.

我想将productid索引为bigint类型值,所以我可以得到jsonb“comment”值来比较这个productid。

postgresql indexing postgresql-9.5
1个回答
0
投票

btree_gin https://www.postgresql.org/docs/9.5/btree-gin.html扩展为许多数据类型提供了gin操作符类,包括bigint。

使用后启用btree_gin扩展后创建索引

CREATE EXTENSION btree_gin;
© www.soinside.com 2019 - 2024. All rights reserved.