This article is half-done without your Comment! *** Please share your thoughts via Comment ***
The PostgreSQL provides Universally Unique Identifier -UUID data type and related functions.
In the previous post, I shared the truth about Universally Unique Identifier - UUID.
You can visit this article here.
PostgreSQL provides two extensions.
1. uuid-ossp
2. pgcrypto.
You can install above extension using below script.
1 2 |
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS pgcrypto; |
I am using pgcrypto extension for generating an UUID.
Below is a small demonstration:
Generate UUID using gen_random_uuid():
1 |
SELECT gen_random_uuid(); |
Create a sample table with UUID Data type:
1 2 3 4 5 |
CREATE TABLE tbl_UUIDSample ( MyUUID UUID PRIMARY KEY DEFAULT gen_random_uuid() ,Name TEXT ); |
Insert sample data:
1 2 3 4 5 |
INSERT INTO tbl_UUIDSample (Name) VALUES ('Anvesh'),('Martin') ,('Roy'),('Jenny') ,('Ronic'),('Monika'); |
The Result:
1 |
SELECT *FROM tbl_UUIDSample; |