Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pG2Pz-0000h4-KP for pgsql-admin@arkaria.postgresql.org; Thu, 12 Jan 2023 18:35:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pG2Py-0007iz-Gd for pgsql-admin@arkaria.postgresql.org; Thu, 12 Jan 2023 18:35:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pG21C-0006d0-7p for pgsql-admin@lists.postgresql.org; Thu, 12 Jan 2023 18:09:38 +0000 Received: from mail-cy.bbox.fr ([194.158.98.48]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pG218-0003Tx-M6 for pgsql-admin@lists.postgresql.org; Thu, 12 Jan 2023 18:09:36 +0000 Received: from mail.jppozzi.dyndns.org (176-172-74-140.abo.bbox.fr [176.172.74.140]) by mail-cy.bbox.fr (Postfix) with ESMTP id CE62745; Thu, 12 Jan 2023 19:09:30 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.jppozzi.dyndns.org (Postfix) with ESMTP id 5AEDC3000E6; Thu, 12 Jan 2023 19:09:30 +0100 (CET) Received: from mail.jppozzi.dyndns.org ([127.0.0.1]) by localhost (mail.jppozzi.dyndns.org [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 85Zu5ouUb7At; Thu, 12 Jan 2023 19:09:27 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.jppozzi.dyndns.org (Postfix) with ESMTP id 5691E30023A; Thu, 12 Jan 2023 19:09:27 +0100 (CET) X-Virus-Scanned: amavisd-new at mail.jppozzi.dyndns.org Received: from mail.jppozzi.dyndns.org ([127.0.0.1]) by localhost (mail.jppozzi.dyndns.org [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id bRoiisX4x6K0; Thu, 12 Jan 2023 19:09:27 +0100 (CET) Received: from mail.jppozzi.dyndns.org (mail.jpp.fr [192.168.2.21]) by mail.jppozzi.dyndns.org (Postfix) with ESMTP id 3EE7E3000E6; Thu, 12 Jan 2023 19:09:27 +0100 (CET) Date: Thu, 12 Jan 2023 19:09:27 +0100 (CET) From: JP Pozzi To: Holger Jakobs Cc: pgsql-admin@lists.postgresql.org Message-ID: <382249592.381.1673546967170.JavaMail.zimbra@jppozzi.dyndns.org> In-Reply-To: References: Subject: Re: MSSQL to PostgreSQL Migration MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.2.8] X-Mailer: Zimbra 8.8.15_GA_4484 (ZimbraWebClient - FF102 (Linux)/8.8.15_GA_4481) Thread-Topic: MSSQL to PostgreSQL Migration Thread-Index: JUshv2diEqLeYpnl7DO7mDB+XiCI5g== X-VADE-SPAMSTATE: clean X-VADE-SPAMSCORE: -100 X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrleeigdduuddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuuefqfggjifgfgffupdcuqfgfvfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvvefkjghfufggtgfgihfothesthhqtgdtredtjeenucfhrhhomheplffrucfrohiiiihiuceojhhpphesjhhpphhoiiiiihdrugihnhgunhhsrdhorhhgqeenucggtffrrghtthgvrhhnpeetvefftdfgveekhfdvtdehhfejkeejkeejkeetuedvgfdtueelveeuleetfeeihfenucffohhmrghinhepihgrnhgrrdhorhhgnecukfhppedujeeirddujedvrdejgedrudegtddpudelvddrudeikedrvddrkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedujeeirddujedvrdejgedrudegtddphhgvlhhopehmrghilhdrjhhpphhoiiiiihdrugihnhgunhhsrdhorhhgpdhmrghilhhfrhhomhepjhhpphesjhhpphhoiiiiihdrugihnhgunhhsrdhorhhgpdhnsggprhgtphhtthhopedvpdhrtghpthhtohephhholhhgvghrsehjrghkohgsshdrtghomhdprhgtphhtthhopehpghhsqhhlqdgrughmihhnsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, You can also look at Postgresql Foreign Data Wrapper (FDW) which can give a= ccess to "foreign" tables even for MSSQL. The transfer will be immediate as : insert into postgres_table select * from mssql_table; Regards JP P ----- Mail original ----- De: "Holger Jakobs" =C3=80: pgsql-admin@lists.postgresql.org Envoy=C3=A9: Jeudi 12 Janvier 2023 18:37:08 Objet: Re: MSSQL to PostgreSQL Migration Am 12.01.23 um 04:21 schrieb Gurudutt Dhareshwar: > For data you can move it using the SQL tool itself=C2=A0or take a BCP Out= =20 > and then insert using the psql -d option . Actually, bcp.exe does not do a very good job. It cannot make a=20 difference between an empty string and a NULL value, for instance. If you try to export in tab-separated format=20 (https://www.iana.org/assignments/media-types/text/tab-separated-values),= =20 carriage returns, newlines, tab character will all mess up the output.=20 And contained backslashes are not doubled as necessary for PG's copy=20 statement. In case your tables aren't too large, you can export via PowerShell=20 keeping the differences between NULL and empty string. The way via JSON=20 may be a bit slow and heavy on memory, though. ### Code for Powershell install-module sqlserver $SqlParams =3D @{ =C2=A0 ServerInstance =3D 'server_name' =C2=A0 UserName =3D 'user_name' =C2=A0 Password =3D 'very_secret' =C2=A0 Database =3D 'db_name' } $tableName =3D 'whatever_tablename' (invoke-sqlcmd @SqlParams -query "Select * from $tableName" |=20 select-object * -excludeproperty=20 itemarray,table,rowerror,rowstate,haserrors |=20 convertto-json).replace('null', '"=C2=A7n=C2=A7"') | convertfrom-json | exp= ort-csv=20 -path "$($tableName).csv" -usequotes asneeded ### import using psql \copy whatever_tablename from whatever_tablename.csv (format csv, header=20 on); Kind Regards, Holger --=20 Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012