0

Its possible to generate uuids with postgres (https://www.postgresqltutorial.com/postgresql-uuid/) Now I need to update my table where uuids are missing. I am not able to figure out how to achieve it. The column individual_uuid has a unique constraint. Any ideas? ??? should be replaced with the syntax I need.

update foo_table set individual_uuid = ???? where individual_uuid is null

not working:

update foo_table set individual_uuid = (SELECT uuid_generate_v1()) where individual_uuid is null

1 Answer 1

2

Usage of SELECT uuid_generate_v1() leads to the unexpected result that the same value gets used for every row, because the subselect is not correlated with values from the main query.

Use uuid_generate_v1() instead:

UPDATE foo_table 
SET    individual_uuid = uuid_generate_v1() 
WHERE  individual_uuid IS NULL;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.