I need to access tables in a remote Postgres database. I spent a couple hours reading through docs last night, and this is what I've come up with.

-- surely this thing is already written somewhere?
CREATE FUNCTION pgsql_fdw_handler()
    RETURNS fdw_handler
    AS '?????' LANGUAGE C STRICT;

-- surely this thing is already written somewhere?
CREATE FUNCTION pgsql_fdw_validator(text[], oid)
    RETURNS void
    AS '????' LANGUAGE C STRICT;

CREATE FOREIGN DATA WRAPPER pgsql
    HANDLER pgsql_fdw_handler
    VALIDATOR pgsql_fdw_validator;

CREATE SERVER products_remote FOREIGN DATA WRAPPER pgsql OPTIONS
    (host 'localhost', dbname 'product_db', port '1234');

CREATE USER MAPPING FOR CURRENT_USER
    SERVER products_remote;

CREATE FOREIGN TABLE products (
  name text,
  id integer
) SERVER products_remote;

select * from products;

I can't figure out what to do for the handler and validator functions, do they exist somewhere? Do I need to write them myself? (what would that look like?) And would appreciate a validation of the overall approach.

I did find this contrib module, but it's apparently incomplete.

share|improve this question

68% accept rate
2  
The dblink module is better suited for that: postgresql.org/docs/current/static/dblink.html – a_horse_with_no_name Jul 26 at 16:01
Thanks, that's what I needed. If you make it a real answer, I'll accept it. – Joshua Cheek Jul 26 at 17:49
Or I can just answer myself if that's more convenient. – Joshua Cheek Jul 26 at 17:50
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.