pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.91k stars 18.03k forks source link

ENH: #44017

Closed rockwayschool closed 3 years ago

rockwayschool commented 3 years ago

This is my first time creating an issue on GitHub. I did not see one like it but if there is, please reference it.

I see a lot of communications about adding upsert features to the to_sql method. I think this is a great idea. I would like to know if there is any possibility of adding functionality to call a stored procedure which takes care of the upsert.

Something like: df.to_sql('mytable', schema='dbo', con=engine, index=False, method='mytable_upsert', stored_proc=True)

I ask because I want to keep my data in a df to upload but I also would like to handle the upsert issues with a stored procedure for performance reasons.

I am using the pymssql driver.

Yes Matthew, I read #14553 and #29636 before creating this. These are very good efforts and I hope they are adopted. The difference with my request is that I would like to be able to call a stored procedure in the database which would handle inserting or updating rows inside the database itself which is faster than issuing a command in python to insert and then finding it exists and then issuing an update on the row. There are ways to do this, just not with a dataframe using to_sql.

mzeitlin11 commented 3 years ago

Thanks for the request @rockwayschool. It would helpful if you can fill in the enhancement form and answer the questions it asks (especially providing a clear, minimal example of why this is useful).

Also please read through the upsert discussions in #14553 and #29636 - is this request asking for something different?

jbrockmendel commented 3 years ago

Pls add an informative title to the issue

mzeitlin11 commented 3 years ago

Closing for now, happen to reopen if you can respond to comments