How to link from Postgresql to SQL Server via ODBC?

linked-server, odbc, postgresql, sql, sql-server

Solution

The two available options are:

- DBI-Link; or

- The ODBC-FDW (SQL/MED foreign data wrapper)

DBI-link is more mature, and will work on Windows. The ODBC FDW is likely to be better once it's properly finished, but at this point it isn't, and AFAIK it is not available on Windows.

See:

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

- http://pgfoundry.org/projects/dbi-link

Problem

I need to be able to query a SQL Server database from within Postgresql. The Postgres instance is running locally and the SQL server set up as an ODBC data source. How do I add this as a linked server? Is there a better approach? Thanks

Original source