我有几个带有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
是不是因为是为组件创建没有索引:
有趣的是,当我尝试以下方法我没有得到这个错误吗?
好的,主要问题是默认的操作符。任何帮助或共享经验,赞赏。 谢谢。