Upsert queries not returning the values after conflicts.
Hi everyone, I'm trying to do query to database which would either create user and return info or select the user if it exists and return values. I came to know about doNothingconflict and it seems to not work with returning values. Could anyone please look into this?
6 Replies
Query is like something like
it should return object containing the entry but it is returning empty as of now.
onConflictDoNothing() will cancel the insert if there’s a conflict, therefore there is nothing to return as nothing has been created. The only way to return is use onConflictDoUpdate() but that has its own issues
I see, what should be the workaround for this issue?
The issue is that you're sort of creating a new row. So it can cause unwanted triggers or alter default sort order and this would now be the last item returned and you have to list all conflicting columns. It just depends on your use case if this is acceptable
What would be most optimal way of handling this?
Doing two calls?
check whether user exists or not and deal with it accordingly?
Just do it inside a transaction and write a separate select statement if the user already exists
Or even better, do the select first and the decide based on what you get
No transactions needed