the table structure is like this:
milliontable(
name varchar(10),
age integer,
joindate date
)
and I want to insert random 1 million data into that table. Is there any way to do that?
Use the random() function to generate random values:
INSERT INTO milliontable (name, age, joindate)
SELECT substr(md5(random()::text), 1, 10),
(random() * 70 + 10)::integer,
DATE '2018-01-01' + (random() * 700)::integer
FROM generate_series(1, 1000000);
It is usually a silly idea to store the age of a person in a table, as this number becomes wrong automatically as time goes by. Use the birthday.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With