简体   繁体   中英

Copy Data from PostgreSQL Direct to MSSQL Similar Table using Query

I have a table in PostgreSQL cpad.mst_Patient PatientID|FirstName|LastName|Gender|Dob|ClinicNumber|Facility|EntryPoint|RegistrationDate|Status|DeleteFlag

I have a similar table in MSSQL that i am doing data migration to. PostgreSQL is live database and i wanted to migrate the new registration from PostgreSQL to MSSQL using script. I am using MSSQL Cursor currently but its tedious because i have to transfer the database from PostgreSQL to Excel then import to MSSQL using integrated services which is time wasting. I need a code that can query data from PostgreSQL and paste it directly into MSSQL.

I am using PostgreSQL 9 and MSSQL 2016

You have a couple of options:

first, you can use a programming language like PHP or python that simply selects * from the postgres table and inserts into the mssql.

Second, you could use a postgres "FDW" (Foreign data wrapper) to set up a database connection from the postgres db to the mysql db using ODBC. Once you get that set up, the FDW makes postgress just see the mysql table as if it were in the postgres db. Then, it's as simple as

insert into mssqltab select * from postgrestab;

Setting up the FDW connection isn't something I'll cover here as most of the config will be determined by how your db and tables are configured.

Of course the third option is not to migrate to mssql because postgresql is a better db, but that's just my opinion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM