We can easily work with UUID data type in PostgreSQL! In this post, we will see all the required steps.
Extension “uuid-ossp” must be installed.
Check the extension:
SELECT * FROM pg_available_extensions;
If not available then run following query to add this:
CREATE EXTENSION "uuid-ossp";
SELECT * FROM pg_extension;
Create a sample table with UUID type primary key-
CREATE TABLE People( id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), age integer );
Now insert into table “People”. Primary key id will be automatically inserted with UUID format value.
INSERT INTO People(age) VALUES (10);
Fetch data from “People” table-
Select * from People;
If you face following error “error: Relation ‘tableName’ does not exist” while you are working with SQL query (but table already in database) then to fix this just write table name in quotation mark i.e. “Book”.
Take a look on following links-