Jes Sie

Jes Sie

  • 737
  • 1.2k
  • 284.6k

Fetch Data From Local Machine DB and Insert To Other Machine DB

Jul 14 2020 5:42 AM
I need to fetch data from my laptop (Postgresql) and insert that to the main server (in a different machine) using also a PostgreSQL. In MSSQL I normally do this:
 
  1. BEGIN TRY  
  2.     BEGIN TRANSACTION  
  3.         INSERT Main_Server.databasename.tbltransactions  
  4.                 SELECT * FROM Local_Server.databasename.tbltransactions  
  5.             WHERE synchronized IS NULL  
  6.   
  7.         UPDATE Local_Server.databasename.tbltransactions SET synchronized = GETDATE() WHERE synchronized IS NULL  
  8.     COMMIT TRANSACTION  
  9. END TRY  
  10.   
  11. BEGIN CATCH  
  12.     ROLLBACK TRANSACTION  
  13.     RAISERROR('There was a problem connecting to the server database. The connection was lost.',16,1)  
  14. END CATCH  
I need to do it using a SQL Transaction. Thank you in advance if you can show or point me to the right direction. I am very newbie in PostgreSql. 

Answers (4)