Skip to content

Commit 7c6fcc0

Browse files
authored
Merge branch 'master' into drop-36
2 parents fa354f7 + e71265b commit 7c6fcc0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

luigi/contrib/postgres.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,15 @@ def copy(self, cursor, file):
356356
else:
357357
raise Exception('columns must consist of column strings or (column string, type string) tuples (was %r ...)' % (self.columns[0],))
358358

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)
363367
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))
369368
cursor.execute(copy_sql, stream=file)
370369

371370
def run(self):

0 commit comments

Comments
 (0)