我試圖從postgres遷移/複製數據到使用python3 vertica(如果還有其他用戶友好的方式,我會很高興聽到他們)。問題是,下面的代碼只有在我從postgres複製一列數據時才起作用。如果我複製多個列,它將不會遷移任何內容。在Vertica表中創建的是空的。從postgres遷移/複製數據到vertica
如何將整個表格從postgres遷移到vertica?
conn = psycopg2.connect()
input = io.StringIO()
cur_postrgres = conn.cursor()
cur_postrgres.copy_expert('''COPY (SELECT id, date from table_1) TO STDOUT;''', input)
cur_postrgres.close()
cur_vertica.execute("DROP TABLE IF EXISTS table_1_temp;")
cur_vertica.connection.commit()
cur_vertica.execute('''CREATE TABLE table_1_temp (
id BIGINT, date TIMESTAMP WITHOUT TIME ZONE);''')
cur_vertica.connection.commit()
#cur_vertica.stdin = input
#input.seek(0)
cur_vertica.copy('''COPY table_1_temp FROM STDIN NULL AS 'null' ''', input.getvalue())
cur_vertica.execute("COMMIT;")
cur_vertica.close()