PostgreSQL two different ways to generate a UUID: gen_random_uuid vs uuid_generate_v4?
-
31-12-2020 - |
Domanda
What is the difference between the following two functions
gen_random_uuid()
provided bypgcrypto
extensionuuid_generate_v4()
provided byuuid-ossp
extension
Are they both the same behind the scenes? Any performance impacts on using one?
Soluzione
Are they the same?
No.
The Postgres documetation for uuid-ossp suggests using gen_random_uuid()
If you only need randomly-generated (version 4) UUIDs,
The uuid-ossp extension also provides other types of UUID (such as mac-addresses based)
The difference?
I looked at the source and discovered that
uuid_generate_v4()
uses arc4random to determine the random part.gen_random_uuid()
uses fortuna instead.
Other than that they do the same job.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange