0

I've been working on a major project that compares data from multiple data sources. I've been using postgres_fdw for this and I've been successful in retrieving data to my local postgres instance from multiple remote postgres servers.

My next step is to do the exact same thing, but to connect to a remote SQL Server. Below is my code that I have used for connecting to remote postgres servers, although I have removed the connection and user details.

CODE

CREATE EXTENSION
IF
    NOT EXISTS postgres_fdw;
CREATE SERVER
IF
    NOT EXISTS remote_mleci_prod FOREIGN DATA WRAPPER postgres_fdw OPTIONS ( HOST '<HOST>', PORT '<PORT>', dbname'<DBNAME>' );
CREATE USER MAPPING
IF
    NOT EXISTS FOR postgres SERVER remote_mleci_prod OPTIONS ( USER '<DB USER>', PASSWORD '<DB PASSWORD>' );
GRANT USAGE ON FOREIGN SERVER remote_mleci_prod TO local_user;
IMPORT FOREIGN SCHEMA PUBLIC 
LIMIT TO ( mle_object, source_mle_mapping, source_object, mle_enrolments ) 
FROM
    SERVER remote_prod_dda INTO PUBLIC;
SELECT
    mo.mle_object_id AS "MLE OBJECT ID",
    mo.mle_id AS "COURSE ID",
    so.source_object_id AS "SOURCE OBJECT ID",
    so.source_id AS "SOURCE ID" 
FROM
    mle_object mo
    LEFT JOIN source_mle_mapping smm ON smm.mle_object_id = mo.mle_object_id
    LEFT JOIN source_object so ON smm.source_object_id = so.source_object_id 
WHERE
    mo.mle_id = 'I3132-CIVL-11130-1221-1YR-037943'

ERROR

ERROR: relation "mle_object" does not exist LINE 7: mle_object mo

The SELECT statement works when running on the actual server.

Can somebody take a look and put me on the right path?

Thanks in advance.

Andrew Stevenson
  • 578
  • 1
  • 9
  • 23
  • 3
    `postgres_fdw` can only connect to a Postgres database. You need a FDW for SQL Server. There [is one](https://github.com/tds-fdw/tds_fdw) but I have no idea how good it is. –  Sep 30 '22 at 17:08
  • I actually thought the FDW was dependant on what database (postgres, oracle, etc) the SQL was being run from rather than what you are connecting too, so thanks for that - Appreciate your comment. I'm not finding how to install tds_fdw on windows. Building the libraries is beyond my expertise. I don't suppose you know how to do this do you? – Andrew Stevenson Oct 03 '22 at 10:34
  • UPDATE: As I am developing on windows, I need to install WSL and a *nix distro. – Andrew Stevenson Oct 20 '22 at 15:02

0 Answers0