我有幾個帶有json列的表,並且想要在這些列上構建索引。但是,我得到一個默認操作員類(http://www.postgresql.org/docs/9.2/static/sql-createopclass.html)。有人已經做過或者給我一個替代方案嗎?在PostgreSQL 9.2的json字段上創建索引
要重現該問題,請嘗試:
>> create table foo (json json, id int);
CREATE TABLE
>> create index on foo (id);
CREATE INDEX
>> create index on foo (json);
ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
這同樣適用於gist
或gil
索引。
>> create type "nested" as (json json, extra text);
CREATE TYPE
>> create table bar (id int, json nested);
CREATE TABLE
>> create index on bar (json);
CREATE INDEX
是不是因爲是爲組件創建沒有索引:
有趣的是,當我嘗試以下方法我沒有得到這個錯誤嗎?
好的,主要問題是默認的操作符。任何幫助或共享經驗,讚賞。 謝謝。