6

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

friartuck
  • 2,954
  • 4
  • 33
  • 67
  • For full and varied answers on generating UUID in PostgreSQL, see: https://stackoverflow.com/q/12505158/6710366 – André Carvalho May 27 '22 at 17:03
  • 1
    Does this answer your question? [Generating a UUID in Postgres for Insert statement?](https://stackoverflow.com/questions/12505158/generating-a-uuid-in-postgres-for-insert-statement) – André Carvalho May 27 '22 at 17:06

2 Answers2

8

Use

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

then you can use uuid_generate_v4().

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
friartuck
  • 2,954
  • 4
  • 33
  • 67
3

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

Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82