PostgreSQL has a function which allows the generation of random UUIDS. This function is helpful when inserting rows into tables and one or a number of columns require UUID values. The function is called: gen_random_uuid().

Example

Let’s say that we are inserting a new row into a table called employees and want to assign as we insert the rows random UUIDs for the employee_id column. Here’s how we would do that:

INSERT INTO employees (employee_id, first_name, middle_initial, last_name, position, department_id, building_id, created_at, updated_at, deleted_at) VALUES
(gen_random_uuid(), "Ahmad", "A", "Abdullah", "Senior Engineer", 2, 5, now(), NULL, NULL);