I have two instances of postgreSQL , one as the data source (port 5433) and the other as data access layer(host of foreign data wrappers on port 5432).
I want to import the schema of postgreSQL table (Dzlog) so that I dont have to map each column in "CREATE FOREIGN TABLE". Therefore, I have the following command:
engine = create_engine('pgfdw://postgres:test123@localhost:5432/mydb')
connection = engine.connect()
connection.execute("""CREATE SERVER pgfdw_server_1 FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (dbname 'sorucedb', port '5433', host 'localhost');""")
connection.execute("""CREATE USER MAPPING FOR postgres SERVER `pgfdw_server_1
OPTIONS (user 'postgres',password 'password')""")`
connection.execute ("""CREATE SCHEMA imported;""")
connection.execute("""IMPORT FOREIGN SCHEMA public LIMIT TO(Dzlog) FROM SERVER pgfdw_server_1 INTO imported;""")
Now, how can I create the foreign table with this imported schema?
Update:
So if by importing foreign schema (Dzlog) the foreign table is already created, I use the following select statement:
connection.execute("""SELECT sheetId FROM importing.Dzlog WHERE dz(30)=-5;""")
ProgrammingError: (psycopg2.ProgrammingError) relation "Dzlog " does not exist
In psql also the relation does not exist