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;
1 |
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.
1 2 3 4 5 6 7 8 |
CREATE TABLE t1 ( id uuid DEFAULT uuid_generate_v4 (), Adı VARCHAR NOT NULL, Soyadı VARCHAR NOT NULL, email_adresi VARCHAR NOT NULL, telefon VARCHAR, PRIMARY KEY (id) ); |
Let’s insert some data into this table and look at the results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
INSERT INTO t1 ( Adi, Soyadi, email_adresi, telefon ) VALUES ( 'Faruk', 'Erdem', 'farukerdemm@outlook.com.tr', '4452' ), ( 'ufuk', 'Erdem', 'jasda@hotmail.com', '787078' ), ( 'Utku', 'Erdem', 'asd@hotmail.com', '4011212' ); |
We can see the uuid values generated automatically as a result of the insert.