#2612Requested

Feature request: `insert_or_update` ("upsert")

Requested on GitHub by jdetter
Energy Committed0TeV

Something like this:

// Pseudocode
func upsert(ctx, primary_key_value, value):
  if ctx.primary_key_column.try_find(primary_key_value):
    // Row with a matching primary key column exists
    ctx.primary_key_column.delete(primary_key_value)
  ctx.primary_key_column.insert(primary_key_value, value)
  

In order to upsert on a column it needs to have a unique constraint on it.

  1. jdetter added the feature-request label Apr 14, 2025
  2. This can probably be implemented for now in module bindings as "try-update, insert on row-doesn't-exist" so that we don't have to add this in the host. If it turns out that this needs to be highly optimized we can add an ABI for it later on.

  3. cloutiertyler closed this as completed May 2, 2025
  4. Reopening, as the linked PR does not include C# support, and is currently marked unstable.

  5. gefjon reopened this May 5, 2025
  6. bfops closed this as completed May 5, 2025
  7. bfops reopened this May 5, 2025
  8. If I may, perhaps the name "InsertOrUpdate" or similar would be better. Yes, it's longer, but there is then no ambiguity on first glance about what the function does.

  9. If I may, perhaps the name "InsertOrUpdate" or similar would be better. Yes, it's longer, but there is then no ambiguity on first glance about what the function does.

    @sunkin351 We did indeed settle on insert_or_update in the unstable Rust implementation, #2678 .

  10. bfops renamed to "Feature request: `insert_or_update` ("upsert")" Jun 19, 2025

Boost this Request

Reopen this request?

The request will return to its prior live status.

Mark as Duplicate

Pick the request that Feature request: `insert_or_update` ("upsert") is a duplicate of. Energy rolls up into that request and GitHub closes the linked issue as a duplicate with a timeline reference to the canonical.

Unmark Duplicate

Restore as an independent request. The linked GitHub issue will be reopened and its duplicate-of relationship cleared. The original timeline entries stay as history; the note below is posted as a follow-up comment.