-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Adding (Insert or update if key exists) option to .to_sql #14553 #29636
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
Changes from all commits
848becc
d9f7c23
f0726b3
c742f47
d2a0c2d
686930c
1f47d45
881a934
c95de1d
0082347
2d85c70
0f32cd0
dc70c40
a7b8e8e
1d936ef
9db2aaa
57a246d
c290a78
35e0fc4
6bcd6c2
00e6319
8d654ca
966a95c
b214a68
41938cd
78f8e86
025b0ef
bbcf92b
73fea73
d8b7686
75e16ff
0dfe913
779818a
3fafc95
d79b970
c38f900
0636332
a15fc2f
6c44506
e409bda
d35e145
8a57126
3c308d3
d4764dc
4396aa3
2b1c797
b23f528
899da90
8ebc256
baad9e3
79ef9c0
d0eb251
b838ef5
17a1d42
a25c2f3
f56b53f
247bec0
51a74a2
91c750b
f940b42
6dedb71
e3809a1
6d692cd
efd2382
c3a6a95
a0ce842
07bc8ca
4822ce0
0fba1b6
c230d16
9a7ef9c
2a078f6
c3c6ed1
79becdc
3b6ca76
61d998f
e454c35
b4c058c
2ed4d32
c33d536
b3bfbcc
fafd646
dbee26b
3a04edd
0b03df7
f2d3596
529e5fb
6d718dc
53e3565
1bff71f
26c0b0f
59c76ac
21a87e1
286e8b8
780fcea
70e0eb1
d4fc6d4
c783496
4f4e9d9
e466ff3
f2bc121
b9bfedc
43353f5
6196c29
b27449e
c8c1826
e28cd9e
197e172
6ebe9e8
b95f6c9
8fa8e0e
1dee409
1f9fca7
2b30a9e
a05937e
67143ff
7e1148e
11f201f
7f0b5dd
e5d5ce7
8123cd7
26faabe
9260eca
ad9f52f
a63a77a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2819,12 +2819,15 @@ def to_sql( | |
schema : str, optional | ||
Specify the schema (if database flavor supports this). If None, use | ||
default schema. | ||
if_exists : {'fail', 'replace', 'append'}, default 'fail' | ||
if_exists : {'fail', 'replace', 'append', 'upsert_overwrite', 'upsert_keep'},\ | ||
default 'fail' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this api is conflating two things. isn't upsert by-definition to overwrite? what is the usecase for 'upsert_keep'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Over the course of this PR I have come to agree that using the term There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that makes sense. |
||
How to behave if the table already exists. | ||
|
||
* fail: Raise a ValueError. | ||
* replace: Drop the table before inserting new values. | ||
* append: Insert new values to the existing table. | ||
* upsert_overwrite: Overwrite matches in database with incoming data. | ||
* upsert_keep: Keep matches in database instead of incoming data. | ||
|
||
index : bool, default True | ||
Write DataFrame index as a column. Uses `index_label` as the column | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may add ambiguity to the
if_exists
argument, as it is referring now to two concepts:Would this be better as a separate
if_row_exists
parameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the documentation says:
So, the documentation should be updated at the least.
However, I think it would be conceptually cleaner to separate table-existence from row collision-checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're making a good point. I will look to incorporate this shortly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On your original proposal, you mentioned using a
method
parameter. That seems like a reasonable name/approach :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brylie I think it is a good point, but I am less sure about the action required.
I have actually sent a full reply here:
#14553 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the "upsert" method in SQL checks on the primary key, how about name the parameter
if_key_exists
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be explicit, the parameters should be something like:
if_table_exists
if_row_exists
Since renaming
if_exists
toif_table_exists
is backwords incompatible, perhaps that rename could be avoided or theif_exists
parameter could be marked as deprecated.What is blocking us from adding a new argument for
if_row_exists
?