I’m using following query in Postgresql to update my users table. The goal is having random gender for each user, but at the end, it sets all users to one of male
or female
value.
UPDATE users
SET gender = (SELECT (array['male', 'female'])[floor(random() * 2) + 1])
WHERE id > 0;
Why this query acts like this? and how can I fix it?
I’ve already tried:
UPDATE users
SET gender = (
SELECT (array['male', 'female'])[floor(random() * 2) + 1]
FROM generate_series(1, 1)
)
WHERE id > 0;
but same result !