Brian Hanf
Brian Hanf

Reputation: 564

Querying data by joining two tables in two databases (different database types) on different servers

I have a MS SQL (SQL Server 2008) database with some data in it and a postgresql (9) database with other data. I need to do some queries to find related data. I know how to link two MS SQL databases together but not sure how to even start with the mixed database types.

The new company I work for has postgresql, I have not worked with it before. The guy I replaced was really the only one here who knew much about it. So no internal resources.

I'm not ready to build a solution in code at this point (.NET), just hoping to have a tool to do some queries.

Postgresql has table Company Company_id, Company_name, ....

MS SQL had table Companies company_name, postgresql_company_id, company_id, ....

Upvotes: 0

Views: 807

Answers (1)

Denis de Bernardy
Denis de Bernardy

Reputation: 78443

If you ever need to run queries from Postgres that pulls data from SQL-Server, you can use foreign data wrappers. The ODBC driver should work fine:

http://wiki.postgresql.org/wiki/Foreign_data_wrappers

I'm not familiar enough with SQL-Server to give an authoritative answer on how to do it the other way around, but since Postgres speaks ODBC, I'm guessing it's close enough to how you make a SQL-Server talk with another one.

Related thread: SQL Server 2012: Add a linked server to PostgreSQL

Upvotes: 2

Related Questions