Skip to content

Commit 0b5f37f

Browse files
committed
feat: add commit_transaction to postgres.to_sql
1 parent eb9386f commit 0b5f37f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

awswrangler/postgresql.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ def to_sql(
502502
chunksize: int = 200,
503503
upsert_conflict_columns: list[str] | None = None,
504504
insert_conflict_columns: list[str] | None = None,
505+
commit_transaction: bool = True,
505506
) -> None:
506507
"""Write records stored in a DataFrame into PostgreSQL.
507508
@@ -542,6 +543,8 @@ def to_sql(
542543
insert_conflict_columns: List[str], optional
543544
This parameter is only supported if `mode` is set top `append`. In this case conflicts for the given columns are
544545
checked for evaluating the insert 'ON CONFLICT DO NOTHING'.
546+
commit_transaction: bool
547+
Whether to commit the transaction. True by default.
545548
546549
Returns
547550
-------
@@ -606,7 +609,8 @@ def to_sql(
606609
sql: str = f"INSERT INTO {_identifier(schema)}.{_identifier(table)} {insertion_columns} VALUES {placeholders}{upsert_str}"
607610
_logger.debug("sql: %s", sql)
608611
cursor.executemany(sql, (parameters,))
609-
con.commit()
612+
if commit_transaction:
613+
con.commit()
610614
except Exception as ex:
611615
con.rollback()
612616
_logger.error(ex)

0 commit comments

Comments
 (0)