0
我試圖複製現有PostgreSQL數據庫的表結構。我目前有2個數據庫,A和B.我使用「pg_dump -s」命令並生成了sql查詢來創建A的表。在我的python腳本中,我有以下代碼在數據庫B中創建相同的結構:使用pg_dump創建Python PostgreSQL表
con2 = psycopg2.connect(database="Archives", user="postgres", password="root", host="127.0.0.1", port="5432")
dbexe = """
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.6.0
-- Dumped by pg_dump version 9.6.0
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
several thousand more lines ...."""
cur2 = con2.cursor()
cur2.execute(dbexe)
print("done")
該代碼似乎運行良好,但當我檢查數據庫BI沒有看到任何表。有關爲什麼會發生這種情況的任何建議?
工作完美,謝謝! –
比您可以將其標記爲最佳答案解決方案;) –