使用Python进行具有特殊字符的批量加载

使用Python进行具有特殊字符的批量加载,python,postgresql,greenplum,bulk-load,Python,Postgresql,Greenplum,Bulk Load,我目前正在使用“copy_from”进行批量加载,但由于数据中存在双引号,因此似乎出现了错误 engineor = create_engine('oracle+cx_oracle://xxxx:xxxx@xxxxx:xxxx/?service_name=xxxxx') sql = "select * from xxxxxx WHERE ROWNUM <= 10" df = pd.read_sql(sql, engineor) enginegp = create_engine('xxxxx

我目前正在使用“copy_from”进行批量加载,但由于数据中存在双引号,因此似乎出现了错误

engineor = create_engine('oracle+cx_oracle://xxxx:xxxx@xxxxx:xxxx/?service_name=xxxxx')
sql = "select * from xxxxxx WHERE ROWNUM <= 10"
df = pd.read_sql(sql, engineor)

enginegp = create_engine('xxxxx@xxxxx:xxxx/xxxx')
connection = enginegp.raw_connection()
output = io.StringIO()
df.to_csv(output, sep='\t', header=False, index=False)
output.seek(0)
output.getvalue()
cur = connection.cursor()
cur.copy_from(output, 'test', null="")
connection.commit()
cur.close()
engineor=创建引擎('oracle+cx_oracle://xxxx:xxxx@xxxxx:xxxx/?服务(名称=xxxxx')

sql=“select*from xxxxxx,其中ROWNUM使用CSV格式,而不是试图伪造postgresql TSV格式。 与CSV不同,TSV不使用引号。TSV格式要求对非打印字符使用C转义符-如果您的数据包含任何新行,您将得到看似短行的结果。如果它包含任何选项卡,您将得到长行

要进行CSV,您需要使用copy_expert,它将授予对postgresql copy命令支持的所有选项的访问权限,包括CSV支持

df.to_csv(output, header=False, index=False)


谢谢,这就解决了这个问题。有什么选项可以在这里指定模式吗?
cur.copy_expert("COPY test FROM STDIN WITH CSV NULL '' ", output)