Re: Read MS-SQL data into Postgres via ODBC link?

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Susan Cassidy <scassidy(at)edgewave(dot)com>
Cc: "JB(at)BlackSkyTech(dot)com" <JB(at)BlackSkyTech(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>, 'Brent Wood' <b(dot)wood(at)niwa(dot)co(dot)nz>
Subject: Re: Read MS-SQL data into Postgres via ODBC link?
Date: 2011-07-05 23:12:18
Message-ID: 77273381-1B0B-463D-BDAF-329F248959B2@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5 Jul 2011, at 23:27, Susan Cassidy wrote:

> >Thanks
> >I’m importing into Postgresql 8.4.8 from MSSQL 2005.
> >
> >I do not have control over the MSSQL server, it is at a customer’s site. I only have access to read-only views on their server, from which I replicate the data to my postgres staging tables.
> >
> >I cannot have the MSSQL server do anything like create .csv files, since it’s not my server and the customer will not do that kind of thing (or create DTS scripts, etc. from the PUSH side).
> >
> >I’m hoping there is a way I can simply SELECT from an ODBC source and use that SELECT as part of a Postgres INSERT statement.
>
> >I don’t use MySQL for anything.
>
> >Thanks much for your response!
> >
> >J
>
> Just connect to both databases (in Perl or Python, or something), do a select on the MSSQL data on the MSSQL handle. When you get the row into a set of column variables, just insert the columns via the Postgres handle into the Postgres database. Simple as pie. You can prepare the INSERT statement so that multiple executions use bind variables. Commit every 1000 rows or whatever.

For those queries you will need a similarly prepared Postgres equivalent of the database schema of course, and quite possibly some conversions from MS-SQL types to Postgres types. It's quite obvious, but mentioning it doesn't hurt anyone, and there could be some caveats in that process. Both databases are fairly SQL compliant though, it's probably an easier conversion than from the mistakenly assumed MySQL from earlier replies :P

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4e139a9a12091547611509!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Brinkman 2011-07-05 23:38:25 Re: Read MS-SQL data into Postgres via ODBC link?
Previous Message Susan Cassidy 2011-07-05 21:27:31 Re: Read MS-SQL data into Postgres via ODBC link?