0

I am trying to run a query using for loop where i need to enter 50 million record and one column as fixed value and other two as incremented , i have tried using this.

FOR i IN 1..10 LOOP
INSERT INTO c
SELECT x,98,now()+ i * interval '1 minute'
FROM generate_series(1,50000000) AS x(msisdn);

It seems not working Kindly help

1
  • 1
    "It seems not working". Hi, and welcome to Stack Overflow. Please explain in detail how exactly what you're trying is "not working". What happens, or does not happen? Are there errors? If so, what's the exact text of the error message? Also, what's your PostgreSQL version? What's the schema of c? (You should usually have a list of column names, e.g. c (col1, col2, col3)). These are questions you will be asked for every post, so please edit your post to include that kind of detail. To learn more, see stackoverflow.com/tour and stackoverflow.com/help/asking Commented Feb 3, 2014 at 12:33

1 Answer 1

1

Do you really need a for loop here?

INSERT INTO c
SELECT msisdn,98,now()::timestamptz(0) + i * interval '1 minute'
FROM generate_series(1,50000000) AS x(msisdn),
     generate_series(1,10) as i;

Make sure it's actually what you want before running it, though, because it's going to take very long. For instance, by running:

SELECT msisdn,98,now()::timestamptz(0) + i * interval '1 minute'
FROM generate_series(1,5) AS x(msisdn),
     generate_series(1,10) as i;
Sign up to request clarification or add additional context in comments.

9 Comments

Yes i want to add these many rows, thanks a lot for this help
this thing is adding 10 rows for 1..10 i just want a single row for every value..
Well... so is your original loop, which is why I was prompting you to make sure it's the query you want. :-)
in a way like 1,98,date then second row is 1,98, date with 1 minute added and like this .. so 50 rows added like this
I want an output in following way 1,98,<time> 2,98,<time+any interval ) 2,98,<time+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.