@@ -356,16 +356,15 @@ def copy(self, cursor, file):
356
356
else :
357
357
raise Exception ('columns must consist of column strings or (column string, type string) tuples (was %r ...)' % (self .columns [0 ],))
358
358
359
- # cursor.copy_from is not available in pg8000
360
- if hasattr (cursor , 'copy_from' ):
361
- cursor .copy_from (
362
- file , self .table , null = r'\\N' , sep = self .column_separator , columns = column_names )
359
+ copy_sql = (
360
+ "COPY {table} ({column_list}) FROM STDIN "
361
+ "WITH (FORMAT text, NULL '{null_string}', DELIMITER '{delimiter}')"
362
+ ).format (table = self .table , delimiter = self .column_separator , null_string = r'\\N' ,
363
+ column_list = ", " .join (column_names ))
364
+ # cursor.copy_expert is not available in pg8000
365
+ if hasattr (cursor , 'copy_expert' ):
366
+ cursor .copy_expert (copy_sql , file )
363
367
else :
364
- copy_sql = (
365
- "COPY {table} ({column_list}) FROM STDIN "
366
- "WITH (FORMAT text, NULL '{null_string}', DELIMITER '{delimiter}')"
367
- ).format (table = self .table , delimiter = self .column_separator , null_string = r'\\N' ,
368
- column_list = ", " .join (column_names ))
369
368
cursor .execute (copy_sql , stream = file )
370
369
371
370
def run (self ):
0 commit comments