In PostgreSQL, I am loading the uuid-ossp extension so I can use the function that creates random UUIDs in my queries:

create extension if not exists "uuid-ossp";

However, as well as making available the one function I need (uuid_generate_v4), it also makes nine other functions that I don't need available:

The functions available in my postgresql gui

(Using \df on the command-line shows the same data). Is there any way I can, using programming terms, "import" just the uuid_generate_v4 function into my "namespace", without importing the ones I'm not using?

  • 4
    You can't. An extension is a single unit (btw: gen_random_uuid() from pgcrypto is a lot faster than uuid_generate_v4) Aug 27, 2019 at 11:25
  • 2
    You can easily write your own function: see e.g. this answer or the other answer Aug 27, 2019 at 11:31
  • Thanks for the tip. I did expect the answer was going to be "you can't, but here's the closest way".
    – Ben S
    Aug 27, 2019 at 11:36
  • Out of curiosity, what problem are you having with the other functions? If they're not being called, they're not going to use any online resources.
    – jmelesky
    Aug 27, 2019 at 15:38
  • You can install extensions into a different schema, to take some of the clutter out of your default schema. You can either do one schema per extension, or just make one schema for all extensions you use.
    – jjanes
    Aug 27, 2019 at 17:30

1 Answer 1


In PostgreSQL 13, the gen_random_uuid() function is now available globally, with no need to use the pgcrypto or uuid-ossp extensions.

It is still not possible to only load one function from an extension, but for this common case, it's possible to generate random UUIDs without having all those other UUID-related functions in scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.