onConflictDoUpdate() ID entry
How to get ID of entry in
onConflictDoUpdate
, where conflict appeared?4 Replies
I’m not sure I understand your question - you shouldn’t need to provide that ID in order to do the update, and you have to explicitly specify the column you’re checking for conflicts on yourself via the target parameter
Maybe it would be helpful to have an example of what you’re trying to do?
I have a local array of objects that also contain an ID. When there is a conflict, I want to get the ID of the item so that I can take the value from this field and update it
this way I can update multiple items in case of multiple conflicts.
This is Postgres, right? I think what you want is to use the virtual EXCLUDED table so that you can reference the other fields of the item that failed to insert to construct the update
I don’t think Drizzle implements that directly right now, but you should be able to do something like
Or it might be
excluded."name"
? Unfortunately I’m not well versed in Postgresyou can do that: https://discord.com/channels/1043890932593987624/1043890932593987627/1143921817002709062
On conflict on products.id, it will update productName.