4

我添加了一个扩展,我的安装显示了已安装的模块,

mydb=# \dx
                                   List of installed extensions
 Name   | Version |   Schema   |                                  Description                            
--------+---------+------------+-------------------------------------------------------------------
pg_trgm | 1.0     | extensions | text similarity measurement and index searching based on trigrams
plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
(2 rows)

但是当我去使用它时,我得到了一个错误,

mydb=# select similarity('hello','hell');
ERROR:  function similarity(unknown, unknown) does not exist
LINE 1: select similarity('hello','hell');
           ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

使用扩展提供的功能还有其他步骤吗?

4

2 回答 2

3

它应该工作。这是一个 psql 协议:(对不起,系统是德语)

str@s131-intel:~> psql
psql (9.2.7)

strobel=# CREATE EXTENSION pg_trgm;
CREATE EXTENSION
strobel=# \df
                                                          Liste der Funktionen
 Schema |          Name          | Ergebnisdatentyp |                            Argumentdatentypen                             |  Typ   
--------+------------------------+------------------+---------------------------------------------------------------------------+--------
 public | flipper                | boolean          |                                                                           | normal
 public | gin_extract_query_trgm | internal         | text, internal, smallint, internal, internal, internal, internal          | normal
 public | gin_extract_value_trgm | internal         | text, internal                                                            | normal
 <cut>
 public | gtrgm_union            | integer[]        | bytea, internal                                                           | normal
 public | set_limit              | real             | real                                                                      | normal
 public | show_limit             | real             |                                                                           | normal
 public | show_trgm              | text[]           | text                                                                      | normal
 public | similarity             | real             | text, text                                                                | normal
 public | similarity_dist        | real             | text, text                                                                | normal
 public | similarity_op          | boolean          | text, text                                                                | normal
(20 Zeilen)

strobel=# select similarity('hallo', 'hello');
 similarity 
------------
   0.333333
(1 Zeile)

错误消息提示您的参数未被视为文本,因此您可能写了一个反引号(重音符号)而不是撇号。

于 2014-04-08T18:14:50.330 回答
3

该模块已安装到架构extensions中。我猜该架构不在您的搜索路径中,因此找不到该功能。尝试

select extensions.similarity('hello','hell');

如果您不想完全限定函数名称,您只需将该架构添加到您的 search_path:

alter user your_pg_user set search_path = public,extensions;

如果这仍然给出错误,您的 Postgres 用户可能没有必要的权限来调用这些函数。在这种情况下,以超级用户身份(通常是postgres)登录并授予权限:

grant all on schema extensions to your_pg_user;
于 2014-04-08T19:23:34.030 回答