Search code examples
postgresqluuid

PostgreSQL has extension 'uuid-ossp' but can't find uuid_generate_v4()


I installed PostgreSql and checked if extention 'uuid-ossp' was there.

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

And I checked the results with sql query.

SELECT * FROM pg_available_extensions;

enter image description here

However, the uuid_generate_v4() function cannot be used when creating a table.

CREATE TABLE my_table
(
  uuid UUID NOT NULL UNIQUE DEFAULT uuid_generate_v4()
);

Error message is below

SQL Error [42883]: ERROR: function uuid_generate_v4() does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.

I'm looking for a solution to this problem. and I confirmed that superuser is executable. How can I enable the user I created to run it?


Solution

  • After making the user a superuser and reconnecting, the uuid_generate_v4() function can be used.

    alter user myuser with superuser;
    

    Is there any way to use it without making it a superuser?

    It was version 9. and I reinstall db version 16. it works with gen_random_uuid().