vendredi 26 mars 2021

SQL Updating with random subselect everytime, giving me same value for all rows

I have a column with 90% null values, I am trying to use the remaining 10% to pick a value randomly everytime and use it to fill the missing vlues in the exact same table.

this is my table

initial table

I am using this query to do it on PostgreSQL :

UPDATE public."Assure"
SET   "codePostal" = ( 
    SELECT "codePostal" 
      FROM public."Assure"
      WHERE "codePostal" is not NULL
      ORDER BY random() * public."Assure"."CodeAssure_id"
      LIMIT 1 )
WHERE "codePostal" is NULL

result :

this is what i get




Aucun commentaire:

Enregistrer un commentaire