I have a table Users
with an integer column named status
and i want to select a random value from integer list (10,20, 30)
and set to status
for each row.
I'm using this:
update "Users" set "status" = i.a from (select a from (SELECT 30 AS a
UNION ALL SELECT 10 AS a
UNION ALL SELECT 20 AS a) as s order by random() limit 1) i
Result:
id | status
1 20
2 20
3 20
-- other rows have the same status value (20)