2

I'm starting from a CSV file with a lot of zipcode in the form:

FROM;TO;CITY
1000;1200;TESTCITY

and I want to insert it in a postgres table with the columns:

  • ZIPCODE : varchar
  • CITYNAME : varchar

So, for each row in the CSV, I must create "TO - FROM" records in the table.

Is there a way to do this with a simple query, like

insert into zipcodes (zipcode, cityname) 
select RANGE(1000;1200), cityname;

1 Answer 1

2

You can try to use generate_series

insert into zipcodes (zipcode, cityname) 
SELECT  num,'TESTCITY' as cityname
FROM    generate_series(1000,1200) num

sqlfiddle

Sign up to request clarification or add additional context in comments.

Comments

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.