mercredi 25 septembre 2019

Randomly insert 1 of 3 declared variables

I have three variables that are declared and have an integer value assigned to them.

I am trying to randomly assign the integer value to a field in an UPDATE statement, but get an error.

This is statement I am trying to execute:

FOR user_record IN (SELECT * FROM users_to_add) LOOP
    UPDATE 
        customer."user"
    SET
        primary_site_id  = ({site_GRO, site_WHS, site_SHR}[])[ceil(random()*3)],
    WHERE
        userid = (SELECT userID FROM customer.user
                  WHERE emailaddress=user_record.email_address);           
END LOOP;

I am getting:

SyntaxError: syntax error at or near "{"

This same format works if the value being randomly selected is a string but since these are variables, the inside curly brackets can't be enclosed in quotes.




Aucun commentaire:

Enregistrer un commentaire