简体   繁体   English

使用查询将数据从PostgreSQL Direct复制到MSSQL相似表

[英]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 我在PostgreSQL中有一个表cpad.mst_Patient PatientID |名字|姓|性别|性别|诊所编号|设施|入口点|注册日期|状态| DeleteFlag

I have a similar table in MSSQL that i am doing data migration to. 我在进行数据迁移的MSSQL中有一个类似的表。 PostgreSQL is live database and i wanted to migrate the new registration from PostgreSQL to MSSQL using script. PostgreSQL是实时数据库,我想使用脚本将新注册从PostgreSQL迁移到MSSQL。 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. 我目前正在使用MSSQL Cursor,但它很乏味,因为我必须将数据库从PostgreSQL转移到Excel,然后使用浪费时间的集成服务导入到MSSQL。 I need a code that can query data from PostgreSQL and paste it directly into MSSQL. 我需要一个可以从PostgreSQL查询数据并将其直接粘贴到MSSQL中的代码。

I am using PostgreSQL 9 and MSSQL 2016 我正在使用PostgreSQL 9和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. 首先,您可以使用PHP或python这样的编程语言,该语言仅从postgres表中选择*并插入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. 其次,您可以使用postgres“ FDW”(外部数据包装器)来建立使用ODBC的从postgres数据库到mysql数据库的数据库连接。 Once you get that set up, the FDW makes postgress just see the mysql table as if it were in the postgres db. 一旦设置完成,FDW就会使postgress仅仅看到mysql表,就好像它在postgres数据库中一样。 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. 设置FDW连接不是我在这里要讲的内容,因为大多数配置将由数据库和表的配置方式决定。

Of course the third option is not to migrate to mssql because postgresql is a better db, but that's just my opinion. 当然,第三个选择是不迁移到mssql,因为postgresql是更好的数据库,但这只是我的意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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