[Postgres] Using uuid-ossp extenstion
PostgreSQL allows you store and compare UUID values but it does not include functions for generating the UUID values in its core.
Instead, it relies on the third-party modules that provide specific algorithms to generate UUIDs. For example the uuid-ossp
module provides some handy functions that implement standard algorithms for generating UUIDs.
To install the uuid-ossp
module, you use the CREATE EXTENSION
statement as follows:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
To generate the UUID values based on the combination of computer’s MAC address, current timestamp, and a random value, you use the uuid_generate_v1()
function:
SELECT uuid_generate_v1();
Update a data:
update Users set user_handle = uuid_generate_v4() where last_name = 'clark';