我添加了一个扩展程序,我的安装显示已安装的模块
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.
是否还有其他步骤可以使用扩展程序提供的功能?
答案 0 :(得分:2)
它应该工作。这是一个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)
错误消息提示您的参数未被视为文本,因此您可能会写一个反引号(重音符号)而不是撇号。
答案 1 :(得分:2)
该模块已安装到架构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;