Skip to content

Commit

Permalink
Merge branch 'master' into drop-36
Browse files Browse the repository at this point in the history
  • Loading branch information
dlstadther authored Dec 4, 2024
2 parents fa354f7 + e71265b commit 7c6fcc0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions luigi/contrib/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,15 @@ def copy(self, cursor, file):
else:
raise Exception('columns must consist of column strings or (column string, type string) tuples (was %r ...)' % (self.columns[0],))

# cursor.copy_from is not available in pg8000
if hasattr(cursor, 'copy_from'):
cursor.copy_from(
file, self.table, null=r'\\N', sep=self.column_separator, columns=column_names)
copy_sql = (
"COPY {table} ({column_list}) FROM STDIN "
"WITH (FORMAT text, NULL '{null_string}', DELIMITER '{delimiter}')"
).format(table=self.table, delimiter=self.column_separator, null_string=r'\\N',
column_list=", ".join(column_names))
# cursor.copy_expert is not available in pg8000
if hasattr(cursor, 'copy_expert'):
cursor.copy_expert(copy_sql, file)
else:
copy_sql = (
"COPY {table} ({column_list}) FROM STDIN "
"WITH (FORMAT text, NULL '{null_string}', DELIMITER '{delimiter}')"
).format(table=self.table, delimiter=self.column_separator, null_string=r'\\N',
column_list=", ".join(column_names))
cursor.execute(copy_sql, stream=file)

def run(self):
Expand Down

0 comments on commit 7c6fcc0

Please sign in to comment.