Skip to content

Commit 59d4e84

Browse files
authored
EHN: allow for to_sql multi method with oracle backend (pandas-dev#51648)
* EHN: allow for to_sql `multi` method with oracle backend * add explanation why conn.execute is used instead of insert.values
1 parent 910fa77 commit 59d4e84

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ enhancement2
7474
Other enhancements
7575
^^^^^^^^^^^^^^^^^^
7676

77+
- :meth:`to_sql` with method parameter set to ``multi`` works with Oracle on the backend
7778
- :attr:`Series.attrs` / :attr:`DataFrame.attrs` now uses a deepcopy for propagating ``attrs`` (:issue:`54134`).
7879
- :func:`read_csv` now supports ``on_bad_lines`` parameter with ``engine="pyarrow"``. (:issue:`54480`)
7980
- :func:`read_spss` now returns a :class:`DataFrame` that stores the metadata in :attr:`DataFrame.attrs`. (:issue:`54264`)

pandas/io/sql.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,12 @@ def _execute_insert_multi(self, conn, keys: list[str], data_iter) -> int:
963963
from sqlalchemy import insert
964964

965965
data = [dict(zip(keys, row)) for row in data_iter]
966-
stmt = insert(self.table).values(data)
967-
result = conn.execute(stmt)
966+
stmt = insert(self.table)
967+
# conn.execute is used here to ensure compatibility with Oracle.
968+
# Using stmt.values(data) would produce a multi row insert that
969+
# isn't supported by Oracle.
970+
# see: https://docs.sqlalchemy.org/en/20/core/dml.html#sqlalchemy.sql.expression.Insert.values
971+
result = conn.execute(stmt, data)
968972
return result.rowcount
969973

970974
def insert_data(self) -> tuple[list[str], list[np.ndarray]]:

0 commit comments

Comments
 (0)