2016-05-11 20 views

回答

1

雖然自己的答案是正確的,有不涉及傾銷到一個文件中,一般更靈活的是一個更好的辦法。

INSERT INTO orders2 SELECT * FROM orders 
0

答案是:

import psycopg2 
from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE 
import sys 
import cStringIO 

con = psycopg2.connect(database="xxxx", user="xxxx", password="xxxx", host="localhost") 
cur = con.cursor() 

input = cStringIO.StringIO() 
cur.copy_expert('COPY (select * from Orders) TO STDOUT', input) 
input.seek(0) 
cur.copy_expert('COPY Orders2 FROM STDOUT', input) 
con.commit() 
相關問題