用于全文搜索的索引列

OTA*_*TAR 9 postgresql indexing

我有col数据类型的列CHARACTER VARYING

我需要将此列gin索引作为索引.如果尝试直接将gin索引设置为列,则返回错误:

data type character varying 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

如果尝试:

 create index col_vector 
 on mytable 
 using gin (to_tsvector(col))
Run Code Online (Sandbox Code Playgroud)

我收到了错误: functions in index expression must be marked IMMUTABLE

如何ginCHARACTER VARYING列创建索引?

ps我需要这个用于全文搜索

Sat*_*ish 15

试试此代码:

CREATE INDEX "name " ON "tablename" USING gin(to_tsvector('english', "columnname"));
Run Code Online (Sandbox Code Playgroud)

  • 这是解释:http://www.postgresql.org/docs/9.3/static/textsearch-tables.html (2认同)