Update and Insert data into a table with information from another bank

Asked

Viewed 554 times

1

I have the following situation:

Bench To and the bank B both with the table customers 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 into the bank’s client table B the data that were in the client table of the bank To and that was the result:

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

My SGDB is Postgresql.

  • 1

    These banks are on the same server or on different servers?

  • Same server @Jefersonalmeida

  • @Anthonyaccioly passed that same link in my reply, in case he really needs to do it

2 answers

1

There are some ways to do this in PostgreSQL. You can use the 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 it or enter it as you need. If you don’t know how to do a command insert or update you can check this on this OS link Inserorupdate

  • I’ll test and say the result, thank you.

  • @Laérciolopes any question or problem just let us know

-1

In my head Voce needs to use a RAD, like Delphi for example and there are several file batch techniques. Actually in Delphi it is very simple to do this and I am working on a project that integrates Firebird and Sqlite

Browser other questions tagged

You are not signed in. Login or sign up in order to post.