Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EHN: allow for to_sql multi method with oracle backend #51648

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enhancement2

Other enhancements
^^^^^^^^^^^^^^^^^^
-
- :meth:`to_sql` with method parameter set to ``multi`` works with Oracle on the backend
-

.. ---------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,8 @@ def _execute_insert_multi(self, conn, keys: list[str], data_iter) -> int:
from sqlalchemy import insert

data = [dict(zip(keys, row)) for row in data_iter]
stmt = insert(self.table).values(data)
result = conn.execute(stmt)
stmt = insert(self.table)
result = conn.execute(stmt, data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this have to be different for Oracle specifically? I thought sqlalchemy should have made this call agnostic to the DB flavor?

Also in regards to testing, we don't really have the capabilities to test oracle but not opposed to accepting as is.

Copy link
Contributor Author

@jacadzaca jacadzaca Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this is different for Oracle specifically since insert(self.table).values(date) instructs SQLAlchemy to produce a multi-row insert statement (e.g. INSERT INTO some_table(col1, col2) VALUES (1, 2), (3, 4)), which are only supported by Oracle 23c+, while passing the insert(self.table) statement in with the data to conn.execute produces an executemany call that Oracle supports.

I've merged main into my branch, could we reopen please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment about the Oracle case why .values(data) isn't used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a merge conflict and some pre-commit errors

return result.rowcount

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