Skip to content
Advertisement

Generate 100 rows with random data using SQL query

I use this SQL query to insert 1 row of data:

INSERT INTO public.tasks (id, business_name, meta_title, status, title, type) VALUES (
    '10'::bigint, 'business name 1'::character varying, 'meta title 1'::character varying, 'active'::character varying, 'title 1'::character varying, 'merchant'::character varying)
    returning id;

Is it possible with 1 SQL query to insert 100 rows with random data into Postgre table?

Advertisement

Answer

INSERT into tasks SELECT generate_series(1,100) AS id, 
md5(random()::text) AS business_name, 
md5(random()::text) AS meta_title,
md5(random()::text) AS status,
md5(random()::text) AS title,
md5(random()::text) AS type 
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement