Insert cities into the database

4

Hello, I am creating a database, and I will have information from Brazilian municipalities, I imagine that I am certainly not the first to need this information, but I am not aware if there is any way to do this automatically, I can download this database, or some SQL script that inserts the information into the database, because doing this manually is not the most advisable.

I'm using postgreSQL 9.3, I have not created the tables for cities yet.

    
asked by anonymous 05.03.2015 / 13:24

4 answers

6

IBGE registration code

link

Copy everything from

CREATE TABLE cidades (
    id integer NOT NULL AUTO_INCREMENT,
    nome varchar(250),
    codigo_ibge integer,
    estado_id integer,
    populacao_2010 integer,
    densidade_demo numeric(10, 2),
    gentilico varchar(250),
    area numeric(10, 3),
    PRIMARY KEY ('id')
);

and runs on your Postgre

  

also copy the CREATE TABLE quoted above

    
05.03.2015 / 13:42
3

The IBGE website provides all cities through some file types. Take a look at this link, which already has sqls for postgre

link

    
05.03.2015 / 13:38
2

I have a sql that I use, however it is for MySql , but I believe that with few changes you can achieve your goal.

The file is available at: link

    
05.03.2015 / 15:23
2

All States and Municipalities (or almost all ...) of Brazil, with the possibility of entering new countries, districts / states and municipalities. (Columns with prefix to facilitate JOINs and maintain organization ...).

If you have problems with accented characters, open the file in any text editor and save it with UTF-8 encoding, which resolves, or copy and paste the code directly into MySQL (without using import ...)

I'll leave the Github project link:

Github - SQL of Tables with Registers of All Countries and Nations (with BACEN Code) + States and Federations (c / DDD and IBGE Code) Brazilian + Cities and Municipalities (c / IBGE Code) Brazilians, including 31 administrative regions of the DF, Islands and Remote Areas of the World.

    
05.03.2015 / 15:56