简体   繁体   English

如何使用扩展名pg_trgm中的%运算符?

[英]How to use % operator from the extension pg_trgm?

I have my pg_trgm module installed. 我安装了pg_trgm模块。

pg_trgm | 1.0     | extensions | text similarity measurement and index ...

The schema set is extensions . 架构集是extensions To use it I have to run something like this select: 要使用它,我必须运行类似这样的选择:

extensions.similarity('hello','hallo');

I'm trying to run a statement using the % operator and got the following message. 我正在尝试使用%运算符运行语句并获得以下消息。

mydb=# select * from rssdata where description % 'Brazil';
ERROR:  operator does not exist: character varying % unknown
LINE 1: select * from rssdata where description % 'Brazil';
                                            ^
HINT:  No operator matches the given name and argument type(s).
You might need to add explicit type casts. 

What is necessary to run % or <-> operators? 运行%<->运算符需要什么?

Most probably this is a problem with the search_path . 很可能这是search_path的问题。 Run: 跑:

SHOW search_path;

Is the schema where you installed pg_trgm included? 包含pg_trgm的架构是否包含在内? If not, include it. 如果没有,请加入。

Alternatively, you can schema-qualify functions - and even operators using the OPERATOR() construct : 或者,您可以使用OPERATOR()构造对模式限定函数 - 甚至运算OPERATOR()

SELECT * FROM rssdata WHERE extensions.similarity(description, 'Brazil') > .8;
SELECT * FROM rssdata WHERE description OPERATOR(extensions.%) 'Brazil';

Makes it independent from the search_path . 使其独立于search_path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM