Uuid is the abbreviation for “universal unique identifier”. It consists of 36 characters, a set of numbers and letters, and its most important feature is: Its extremely unique.
To use this feature on PostgreSQL, we need to install uuid-ossp extension.
We can install extension with the following command;
CREATE EXTENSION "uuid-ossp";
After running the command above, we see that it was created as follows.
We created the Extension.
Let’s create a uuid value using the uuid_generate_v1 () function in order to test this data type.
The uuid_generate_v1 () function creates the new UUID, based on the combination of the computer’s mac address, the current timestamp, and the random value.
We are creating a table named t1 and we are creating a UUID data type column for this table.
CREATE TABLE t1 (
id uuid DEFAULT uuid_generate_v4 (),
Adı VARCHAR NOT NULL,
Soyadı VARCHAR NOT NULL,
email_adresi VARCHAR NOT NULL,
PRIMARY KEY (id)
Let’s insert some data into this table and look at the results.
We can see the uuid values generated automatically as a result of the insert.