active_record_upsert icon indicating copy to clipboard operation
active_record_upsert copied to clipboard

Return number of inserted/updated records?

Open hammady opened this issue 3 years ago • 0 comments

Is it possible to return the number of inserted records (or updated ones) as a result of executing the upsert statement? For example, when the INSERT succeeds, it could set an instance variable: __inserted: 1. If there was a conflict and there was a ON CONFLICT DO UPDATE, the number of updated records are set: __updated: 1. If there was a WHERE clause in the update which caused the update not to go through the value would be __updated: 0. I inspected the generated statement and I could see RETURNING *, xmax = 0, so probably the last boolean can indicate insertion count?

hammady avatar Aug 04 '21 23:08 hammady