Postgresql – Cannot run ‘uuid-ossp’ functions even when it’s activated

postgresqlpostgresql-extensionsuuid

I want to generate a v4 uuid in PostgreSQL using the extension uuid-ossp, so in psql I ran:

CREATE EXTENSION "uuid-ossp";

Then I ran SELECT uuid_generate_v1(); or SELECT uuid_generate_v4(); but I always get this error:

ERROR:  function uuid_generate_v1() does not exist
LINE 1: select uuid_generate_v1();
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

So how can I solve this error?

Best Answer

There are several possibilities:

  • you ran CREATE EXTENSION in a different database (postgres?)

  • you installed the extension in a schema that is not on the user's search_path.

Use

\dx "uuid-ossp"

in psql to see where the extension is installed.