friartuck
friartuck

Reputation: 3121

Generate a UUID in Postgres

My tables make use of UUID values. I am inserting rows using SQL SQLWorkbench/J but I don't see how I can generate UUIDs when performing a SQL INSERT INTO (-want-to-generate-uuid-here, '5', 'some value'). Is there a way to generate UUIDs with SQLWorkBench/J?

Thanks

Upvotes: 9

Views: 28260

Answers (3)

Jackkobec
Jackkobec

Reputation: 6745

The simplest solution is gen_random_uuid():

insert into tableName (id)
values (gen_random_uuid())

Upvotes: 0

Svetlin Zarev
Svetlin Zarev

Reputation: 15693

Since Postgres 13, UUIDs can be geneerated with gen_random_uuid () without needing the uuid-ossp extension

Upvotes: 10

friartuck
friartuck

Reputation: 3121

Use

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

then you can use uuid_generate_v4().

Upvotes: 11

Related Questions