Refresh and insert data into a table with information from another in another database

1

I have the following situation:

Bank and the B bank both with the Customers table with the following data:

A.clientes                    B.clientes

id    | nome                  id    | nome
-------------------           -------------------
1     | Lucas                 1     | Mauro
5     | Marcos                3     | Sergio
8     | Paulo                 

I would like a command to update and insert the data that was in the clients table of the A database into the clients table of the B database and that this was the result:

B.clientes
id    | nome
-------------------
1     | Lucas    <- UPDATE
3     | Sergio   
5     | Marcos   <- INSERT
8     | Paulo    <- INSERT

My SGDB is PostgreSQL.

    
asked by anonymous 12.01.2017 / 15:45

2 answers

1

There are a few ways you can do this in PostgreSQL . You can use dblink for example.

insert into clientes
select *
from dblink('dbname=postgres hostaddr=xxx.xxx.xxx.xxx dbname=A user=postgres',
            'select id,nome from clientes')
       as t1(id int,nome text);

With this command above you could consult the information in the other bank and update them or insert them as you need them. If you do not know how to do a command of insert or update you can check this on this link in the SO InserOrUpdate

    
12.01.2017 / 16:04
-1

In my head you need to use a RAD, such as delphi for example and there are several file batching techniques. Actually in delphi it's pretty simple to do this and I'm working on a project that integrates Firebird and SQLite

    
12.01.2017 / 15:58