Generate default UUID values ​​for each row in a UUID type column in H2 Database Engine

In the H2 database in the table with the Type UUID column , how do we indicate that we want H2 to generate the default UUID value when INSERTomits this field?

I know how to create a UUID . I read the question, How to insert a specific UUID into the h2 database? .

My question is how to get H2 to generate a UUID value on my behalf.

+5
source share
1 answer

You can use the built-in function RANDOM_UUID():

create table test(id int primary key, data uuid default random_uuid());
insert into test(id) values(1);
select * from test;

, UUID ( ) , ( , H2).

+10

Source: https://habr.com/ru/post/1663574/


All Articles