我有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。
btree_gin https://www.postgresql.org/docs/9.5/btree-gin.html扩展为许多数据类型提供了gin操作符类,包括bigint。
使用后启用btree_gin扩展后创建索引
CREATE EXTENSION btree_gin;