Reputation: 2967
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
Upvotes: 0
Views: 1497
Reputation: 21905
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;
Upvotes: 2