csv to Postgres

I attended a coding event in San Jose called Code For San Jose. It’s a civic minded group that tries to use technology to improve society. They had a number of problems and projects going on, but the main focus that day was on traffic issues. They are trying to increase safety particularly for pedestrians.

I worked in a group and our focus was on analyzing traffic collision data with public school locations. We discussed what type of things we could do with the information and who the consumer of the end product would be. The event is on-going and happens every two weeks. I think I will keep attending and continue to work on this.

One of the things I had to figure out was how to import a csv file to a postgres database table. I wanted to do this so I could potentially calculate the radius between collisions and school addresses. I figured out how to do this by first creating a table and defining the columns and then using the copy code below.

copy [tablename] from '[path]' with delimiter ',' csv header;  

I also had to copy the file to a public user directory as postgres didn’t have permission to access the folder it was initially in.