Skip to content

Instantly share code, notes, and snippets.

@marcellobenigno
Created September 11, 2024 18:47
Show Gist options
  • Save marcellobenigno/dc766e6121e7b2aa4c98f1ef2f768a7d to your computer and use it in GitHub Desktop.
Save marcellobenigno/dc766e6121e7b2aa4c98f1ef2f768a7d to your computer and use it in GitHub Desktop.
Copiando dados de uma tabela de um banco PostgreSQL para outro
-- CREATE EXTENSION dblink;
-- Inserindo no SIG-ITR
TRUNCATE maps_incrasigef CASCADE;
INSERT INTO maps_incrasigef (id,
parcela_co, rt, art, situacao_i, codigo_imo, data_submi, data_aprov, status, nome_area, registro_m, registro_d, municipio, uf_id, geom)
SELECT * FROM dblink(
'dbname=teste_sigef host=localhost user=postgres password=postgres',
'SELECT
id,
parcela_co,
rt,
art,
situacao_i,
codigo_imo,
data_submi,
data_aprov,
status,
nome_area,
registro_m,
registro_d,
municipio,
uf_id,
geom
FROM mapas_sigef'
)
AS maps_incrasigef(
id integer,
parcela_co varchar(64),
rt varchar(4),
art varchar(80),
situacao_i varchar(25),
codigo_imo varchar(13),
data_submi date,
data_aprov date,
status varchar(32),
nome_area varchar(254),
registro_m varchar(254),
registro_d date,
municipio numeric(9),
uf_id numeric(9),
geom geometry(MultiPolygon,4326)
);
-- Inserindo no GEOFAZENDAS
TRUNCATE mapas_incrasigef;
INSERT INTO mapas_incrasigef (id,
parcela_co, rt, art, situacao_i, codigo_imo, data_submi, data_aprov, status, nome_area, registro_m, registro_d, municipio, uf_id, geom)
SELECT * FROM dblink(
'dbname=teste_sigef host=localhost user=postgres password=postgres',
'SELECT
id,
parcela_co,
rt,
art,
situacao_i,
codigo_imo,
data_submi,
data_aprov,
status,
nome_area,
registro_m,
registro_d,
municipio,
uf_id,
geom
FROM mapas_sigef'
)
AS mapas_incrasigef(
id integer,
parcela_co varchar(64),
rt varchar(4),
art varchar(80),
situacao_i varchar(25),
codigo_imo varchar(13),
data_submi date,
data_aprov date,
status varchar(32),
nome_area varchar(254),
registro_m varchar(254),
registro_d date,
municipio numeric(9),
uf_id numeric(9),
geom geometry(MultiPolygon,4326)
);
-- Inserindo no SIG-CTRM
TRUNCATE mapas_incrasigef;
INSERT INTO mapas_incrasigef (id,
parcela_co, rt, art, situacao_i, codigo_imo, data_submi, data_aprov, status, nome_area, registro_m, registro_d, municipio, uf_id, geom)
SELECT * FROM dblink(
'dbname=teste_sigef host=localhost user=postgres password=postgres',
'SELECT
id,
parcela_co,
rt,
art,
situacao_i,
codigo_imo,
data_submi,
data_aprov,
status,
nome_area,
registro_m,
registro_d,
municipio,
uf_id,
geom
FROM mapas_sigef'
)
AS mapas_incrasigef(
id integer,
parcela_co varchar(64),
rt varchar(4),
art varchar(80),
situacao_i varchar(25),
codigo_imo varchar(13),
data_submi date,
data_aprov date,
status varchar(32),
nome_area varchar(254),
registro_m varchar(254),
registro_d date,
municipio numeric(9),
uf_id numeric(9),
geom geometry(MultiPolygon,4326)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment