Postgres中与pg_trgm的相似函数 [英] Similarity function in Postgres with pg_trgm

查看:195
本文介绍了Postgres中与pg_trgm的相似函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Postgres中使用相似性函数进行一些模糊的文本匹配,但是每当我尝试使用它时,都会出现错误:

I'm trying to use the similarity function in Postgres to do some fuzzy text matching, however whenever I try to use it I get the error:

function similarity(character varying, unknown) does not exist

如果我添加显式强制转换为文本我得到错误:

If I add explicit casts to text I get the error:

function similarity(text, text) does not exist

我的查询是:

SELECT (similarity("table"."field"::text, %s::text)) AS "similarity", "table".* FROM "table" WHERE similarity > .5 ORDER BY "similarity" DESC LIMIT 10

我需要做些什么来初始化pg_trgm吗? / p>

Do I need to do something to initalize pg_trgm?

推荐答案

您必须安装pg_trgm。在debian中,源此sql: /usr/share/postgresql/8.4/contrib/pg_trgm.sql 。从命令行:

You have to install pg_trgm. In debian, source this sql: /usr/share/postgresql/8.4/contrib/pg_trgm.sql. From the command line:

psql -f /usr/share/postgresql/8.4/contrib/pg_trgm.sql

或在psql shell中:

Or inside a psql shell:

\i /usr/share/postgresql/8.4/contrib/pg_trgm.sql

该脚本默认为安装在公共架构中,如果您想将其安装在其他位置,则在顶部编辑搜索路径(这样,只需删除架构即可完成卸载/升级)。

The script defaults to installing in the public schema, edit the search path at the top if you want to install it somewhere else (so that uninstalling/upgrading can be done simply by dropping the schema).

这篇关于Postgres中与pg_trgm的相似函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆