0

To test a report against data, I want to INSERT test data into a table in Postgres SQL.

For example:

INSERT INTO call_logs (phonenumber,timeofcall) VALUES ('+12121001001','2014-12-23T07:01:00.000+00:00')

But I want to loop, say, 59 times, to have phone numbers 2121001001, 1002, 1003, etc with times of call 07:01, 07:02, 07:03, etc.

How do I do that with a loop?

Thanks.

1 Answer 1

3

You do not need a loop. Use generate_series:

insert into call_logs (column1, phonenumber,timeofcall)
select
    'constant_value',
    '+' || generate_series(12121001001, 12121001059),
    generate_series(
        '2014-12-23t07:01:00.000+00:00'::timestamp,
        '2014-12-23t07:59:00.000+00:00',
        '1 minute'
    )
Sign up to request clarification or add additional context in comments.

2 Comments

Will that increase the phone number too? 212-100-1001, 212-100-1002, etc. And also, I left a few columns out for simplicity, but I do have a few other columns that will not change the value, though. How will the SQL statement be then? Thanks.

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.