用于全文搜索的索引列

时间:2013-05-13 08:56:20

标签: postgresql indexing

我的列col的数据类型为CHARACTER VARYING

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

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))

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

如何为gin列创建CHARACTER VARYING索引?

P.S。我需要这个用于全文搜索

1 个答案:

答案 0 :(得分:13)

试用此代码:

CREATE INDEX "name " ON "tablename" USING gin(to_tsvector('english', "columnname"));