Detect when onConflictDoUpdate does a insert vs a update
Hi,
I was wondering if there is anyway to know when a onConflictDoUpdate does a update vs a insert.
Thanks!
3 Replies
I don't think there is a way. The output is the same either way. Something like this (without
.returning()
)
You can try it here: https://drizzle.run/gixu7ads36xwsx06xedd7q1e
Try running it with id: 1
, which conflicts, and without.
Alternative would be to run a select query to check for conflicting records, before running the insert or update.You can keep an
updatedAt
column in your table, and include it in your returning
clause, then compare to timestamp cached before you ran the query.You can still use the returning trick even if you don't have an updatedAt column by using the
excluded
table to compare what's returned