Skip to content

Instantly share code, notes, and snippets.

@mistificator
Created November 3, 2021 15:19
Show Gist options
  • Save mistificator/ba6ba0a1e563ce0914814c8d03be43c7 to your computer and use it in GitHub Desktop.
Save mistificator/ba6ba0a1e563ce0914814c8d03be43c7 to your computer and use it in GitHub Desktop.
PostgreSQL select table from foreign server
DROP FOREIGN TABLE IF EXISTS server2_cdg_types;
DROP USER MAPPING IF EXISTS FOR postgres SERVER server2;
DROP SERVER IF EXISTS server2;
DROP EXTENSION IF EXISTS postgres_fdw;
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
CREATE SERVER server2
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '127.0.0.1', port '5432', dbname 'postgres');
CREATE USER MAPPING FOR postgres
SERVER server2
OPTIONS (user 'postgres', password 'postgres');
CREATE FOREIGN TABLE server2_cdg_types (
"ID" serial NOT NULL,
"Description" text
)
SERVER server2 OPTIONS (schema_name 'public', table_name 'cdg_types');
SELECT * FROM server2_cdg_types;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment