I have foo
table and would like to set bar
column to a random string. I've got the following query:
update foo
set bar = select string_agg(substring('0123456789bcdfghjkmnpqrstvwxyz', round(random() * 30)::integer, 1), '')
from generate_series(1, 9);
But it generates the random string once and reuse it for all rows. How can I make it to generate one random string for each row?
I know I can make it a function like this:
create function generate_bar() returns text language sql as $$
select string_agg(substring('0123456789bcdfghjkmnpqrstvwxyz', round(random() * 30)::integer, 1), '')
from generate_series(1, 9)
$$;
and then call the function in the update query. But I'd prefer to do it without a function.