File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -502,6 +502,7 @@ def to_sql(
502
502
chunksize : int = 200 ,
503
503
upsert_conflict_columns : list [str ] | None = None ,
504
504
insert_conflict_columns : list [str ] | None = None ,
505
+ commit_transaction : bool = True ,
505
506
) -> None :
506
507
"""Write records stored in a DataFrame into PostgreSQL.
507
508
@@ -542,6 +543,8 @@ def to_sql(
542
543
insert_conflict_columns: List[str], optional
543
544
This parameter is only supported if `mode` is set top `append`. In this case conflicts for the given columns are
544
545
checked for evaluating the insert 'ON CONFLICT DO NOTHING'.
546
+ commit_transaction: bool
547
+ Whether to commit the transaction. True by default.
545
548
546
549
Returns
547
550
-------
@@ -606,7 +609,8 @@ def to_sql(
606
609
sql : str = f"INSERT INTO { _identifier (schema )} .{ _identifier (table )} { insertion_columns } VALUES { placeholders } { upsert_str } "
607
610
_logger .debug ("sql: %s" , sql )
608
611
cursor .executemany (sql , (parameters ,))
609
- con .commit ()
612
+ if commit_transaction :
613
+ con .commit ()
610
614
except Exception as ex :
611
615
con .rollback ()
612
616
_logger .error (ex )
You can’t perform that action at this time.
0 commit comments