如何在mac os上的postgresql上安装fuzzystrmatch.sql pg_trgm.sql x

根据这个我已经安装了postgresql,但是我也需要模糊string匹配function,但是我不知道如何安装这些。

对于Mac,.sql文件位于/Library/PostgreSQL/8.3/share/postgresql/contrib文件夹中

如果你想在postgresql 9.1的 fuzzystrmatch包中寻找levenshtein或其他函数,只需要这样做:

 #用postgres用户和:
 psql my_database -U postgres
 #inputpostgres密码并inputpsql shell:
 CREATE EXTENSION fuzzystrmatch;

完成。

如果你找不到扩展名,可能你没有安装postgres contrib。

例如,在centos style os上:

yum install postgresql93-contrib 

根据Rails迁移情况下的答案,所需要的是:

 create extension fuzzystrmatch; create extension pg_trgm; 

通常用一个充满函数的sql文件,就是这样的:

 cat fuzzystrmatch.sql | psql {database name}