-
Notifications
You must be signed in to change notification settings - Fork 104
Ability to explicitly set insert_fields and update_fields #56
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
Comments
It would be super if one could pass For example, as shown in this SQL snippet: INSERT INTO foo_bar (
a, b, c, d, e
) VALUES (
..., ..., ..., ..., ...
)
ON CONFLICT (a)
DO UPDATE SET
conflicted_at = CLOCK_TIMESTAMP()
WHERE ... Maybe something like this? (
MyModel.objects.on_conflict(['name'], ConflictAction.UPDATE)
.bulk_insert([
dict(name='swen'),
dict(name='henk'),
dict(name='adela')
]).conflict_update([
dict(foo='aa'),
dict(foo='bb'),
dict(foo='cc')
])
) |
Does this issue have any chance? Very good if it will support F expression. My current task require insert default value or update existed row with |
Need the same thing, upsert doesn't work with F() expressions |
Great library! However, the upsert implementation is not complete without the ability to explicitly set update fields (ie the DO UPDATE clause). It should also be made clear that upsert_* and insert_* are the same (consider removing one- it's confusing as is). Once this has been sorted out, we can put it forward for inclusion in |
Yeah, it relies on sort of "guessing" - see "magical fields" in the code...Whenever you encounter the word "magic" in software, you should be alarmed :) |
I have my own homegrown bulk_upsert which is much simpler, it has |
I've taken a shot at this because I had a need for it: #189 |
My case is that I want to
bulk_upsert
a bunch of (Django) user entries.Both when inserting and updating, the password should not be set. For some reason (I didn't investigate why) the resulting SQL query has
password
as insert field, even though it's not part of the dicts passed to bulk_upsert.I'd like to have keyword arguments
insert_fields
andupdate_fields
which are used instead of_get_upsert_fields
if specified, in case you know what you're doing. Moreover, there could be cases where the insert and update really take different fields.The text was updated successfully, but these errors were encountered: