mercredi 15 janvier 2020

Updating a postgresql column with a random element from a list of strings

I would like to randomly update the registered_party column of each row in my table named table_name with a string from this list ['republican', 'democrat']. I am running into a syntax error. How can I fix the query so that it achieves the goal.

 Update table_name set registered_party =
  select from (unnest(ARRAY['republican','democrat'])
   FROM generate_series(1, 10)
  ORDER BY random() )
  LIMIT 10;



Aucun commentaire:

Enregistrer un commentaire