Search code examples
postgresqlschemapostgresql-extensions

How do I use an extension installed in a different schema?


I added an extension and my install shows the module installed,

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)

But when I go to use it I'm getting an error,

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.

Is there any other step to use the functions the extension provides?


Solution

  • The module was installed into the schema extensions. I guess that that schema is not in your search path and therefor the function is not found. Try

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

    If you don't want to fully-qualify the function names you can simply add that schema to your search_path:

    alter user your_pg_user set search_path = public,extensions;
    

    If that still gives an error your Postgres user might not have the necessary privileges to call the functions. In that case log in as the superuser (typically postgres) and grant the priviliges:

    grant all on schema extensions to your_pg_user;