【发布时间】:2017-02-19 15:59:56
【问题描述】:
我有product_reviews TABLE 和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
-
当我用 BTREE 更改 GIN 时,没有给出错误...
-
但是为什么我不能像我的例子那样使用 GIN?
-
通常 GIN,GiST 索引用于未定义操作
<或>的类型。定义这些操作后,您可以使用 BTREE 索引。几乎所有类型都支持 GIN、GIST 索引或 BTREE 索引 - 不是两种情况。 -
数组可以有 GIN 或 GiST 索引。这些索引在结果长度和数组长度方面具有不同的行为。您应该检查极端情况。
标签: postgresql indexing postgresql-9.5