0

I need to generate an uuid that does not exist in a certain column in a table. I found a function gen_random_uuid(). Is there some way in the loop to check if such an uuid exists and replace it if it does?

CREATE TABLE x (id UUID PRIMARY KEY, name TEXT) INSERT INTO x VALUES ( gen_random_uuid(), // Need to check if uuid not exist in id column 'some name' ) 

1 Answer 1

3

There are more uuid than atoms in the universe. So the chance of randomly picking the same twice is virtually zero. That is exactly the point of uuid, you do not have to check that they are unique. You just assume they are by construction.

Sign up to request clarification or add additional context in comments.

1 Comment

I understand that the probability of repetition tends to zero, but it is still not zero. I would like to be sure that nothing is faulty) But okay, I will assume that they will always be unique. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.