mardi 10 mai 2016

Update table using different random values for each update row

I want to update random 20% values of a table in Postgres, I want to assign for this attribute the old attribute + a random number with specific limits, and I want that for each row this random number must be different.

I am currently doing this:

update tab_ex
set val = (SELECT val + (SELECT random()*2000 FROM generate_series(20,2000) LIMIT 1))
where id in (select id from tab_ex order by random() limit (select count(*)*0.2 from tab_ex));

and it is updating 20% of my table however it is updating with a specific random number for every row instead of changing this random number for each update.




Aucun commentaire:

Enregistrer un commentaire