2

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?

2
  • What do you mean by random data? Commented Aug 31, 2021 at 0:29
  • random characters of data Commented Aug 31, 2021 at 0:29

1 Answer 1

5
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 
Sign up to request clarification or add additional context in comments.

2 Comments

For Date field how I can generate random date?
You can do different things with random() function and dates. I.e. if you want random day from the last year, you can do something like this: select date(now() - floor(random() * 365) * '1 day'::interval)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.