Skip to content

Commit 25ff7cb

Browse files
committed
Generate a copy statement
Create a variation of generate_insert_statement that returns a PostgreSQL copy statement, suitable for bulk loading of data formatted as csv.
1 parent 1e59be2 commit 25ff7cb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

target_postgres/sinks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,25 @@ def column_representation(
259259
)
260260
return columns
261261

262+
def generate_copy_statement(
263+
self,
264+
full_table_name: str,
265+
columns: List[sa.Column],
266+
) -> str:
267+
"""Generate a copy statement for bulk copy.
268+
269+
Args:
270+
full_table_name: the target table name.
271+
columns: the target table columns.
272+
273+
Returns:
274+
A copy statement.
275+
"""
276+
columns_list = ", ".join((f'"{column.name}"' for column in columns))
277+
sql: str = f"copy {full_table_name} ({columns_list}) from stdin with csv"
278+
279+
return sql
280+
262281
def generate_insert_statement(
263282
self,
264283
full_table_name: str,

0 commit comments

Comments
 (0)