postgresql 全文搜索的索引列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16518176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:54:45  来源:igfitidea点击:

Indexing column for full text search

postgresqlindexing

提问by Oto Shavadze

I have column colwith data type CHARACTER VARYING

我有col数据类型的列CHARACTER VARYING

I need that index this column as ginindex. If trying directly set gin index to column, returned error:

我需要将该列作为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

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

If trying:

如果尝试:

 create index col_vector 
 on mytable 
 using gin (to_tsvector(col))

I got error: functions in index expression must be marked IMMUTABLE

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

How to create ginindex for CHARACTER VARYINGcolumn ?

如何ginCHARACTER VARYING列创建索引?

p.s. I need this for full text search

ps 我需要这个进行全文搜索

回答by Sathish

Try This Code:

试试这个代码:

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