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.