I'm using postgres 10 and I'm looking to randomise some data.
I start by creating a temporary table and fill it with 1,000 rows of random data.
I then want to merge that into another table that may have less or more rows than the random data.
For each row in my dimension table I want to select a random row from the random data in the temporary table, setting the values in the dimension table to the randomly selected rows values in the temporary table.
eg.
I have a table called reference.tv_shows with the fields Name and Category.
I have a temporary table called random_tv_shows with the fields Name and Category. This data is completely random and consists of 1,000 rows.
I want to go through EACH row in the reference.tv_shows and pick a random row in the random_tv_shows table and set the reference.tv_shows Name and Category to be that of the selected row in random_tv_shows.
I tried running a fairly simple select but it looks as though it evaluates itself once then updates (Or maybe RANDOM() is only random once per TX?).
UPDATE reference.tv_shows SET "Name" = (SELECT "Name" FROM random_tv_shows ORDER BY RANDOM() LIMIT 1)
Is there a way to do this in postgres?
random_tv_shows) ?