我可以使用s3将数据从一个psycopg2桶复制到一个红移表中
import psycopg2
sql = """ copy table1 from 's3://bucket/myfile.csv'
access_key_id 'xxxx'
secret_access_key 'xxx' DELIMITER '\t'
timeformat 'auto'
maxerror as 250 GZIP IGNOREHEADER 1 """
cur.execute(sql)如何字符串多个redshift语句来执行以下三项操作:
我尝试了以下几点:
sql = """ copy table1 from 's3://bucket/myfile.csv'
access_key_id 'xxxx'
secret_access_key 'xxx' DELIMITER '\t'
timeformat 'auto'
maxerror as 250 GZIP IGNOREHEADER 1
create table table2 as table1
drop table table1"""我没有得到任何错误,但表没有创建,只有副本是从上面工作的。我在sql中做错了什么?
发布于 2018-07-17 12:30:23
下面的代码通过创建一个重复的副本来执行Copy from Table1到Table2。然后,删除Table1。
import psycopg2
def redshift():
conn = psycopg2.connect(dbname='***', host='******.redshift.amazonaws.com', port='5439', user='****', password='*****')
cur = conn.cursor();
cur.execute("create table table2 as select * from table1;")
cur.execute(" drop table table1;")
print("Copy executed fine!")
redshift()https://stackoverflow.com/questions/51380648
复制相似问题