mysqlpostgresqljoinheterogeneous

Joining tables from Postgres to MySQL using mysql_fdw or


I have a table in Postgres that I need to reflect in MySQL. I found this http://wiki.postgresql.org/wiki/Foreign_data_wrapper#mysql_fdw though the directions are very unclear how to actually link to MySQL. CREATE FOREIGN TABLE works in Postgres but is a syntax error in MySQL. After running running all of the CREATE FOREIGN TABLE and creating the CREATE SERVER mysql_svr in Postgres, no data magically appear in MySQL, so I must be missing a step, they don't provide.

mysql> CREATE FOREIGN TABLE ex_staff ( id integer, name text, address text) SERVER mysql_svr OPTIONS (query ‘SELECT * FROM hr.employees WHERE date_left IS NOT NULL’);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN TABLE ex_staff ( id integer, name text, address text) SERVER mysql_svr O' at line 1

Solution

  • doh...

    OPTIONS (
        database 'myplace',
        schema 'test', 
        table 'dblist', 
        sql_query 'select description,id,name,created_datetime,sd,users from `test`.`dblist`',
        sql_count 'select count(id) from `test`.`dblist`',
        db_id 'id', 
        db_name 'name',
        db_desc 'description',
        db_users 'users',
        db_createdtime 'created_datetime'
    );