Skip to content
This page View Markdown Open in ChatGPT Open in Claude

upsert

upsert=true makes update by id and replace by id insert a row when the id does not exist. Without it (the default, false), an unknown id changes nothing and answers data: null.

PUT /api/schema/admin/mysql8/inventory/customers/update-by-id/999?upsert=true
Body
{ "first_name": "John", "last_name": "Sina", "pincode": 382350, "isActive": 0 }
Row 999 What happens Answer
exists updated with the body the row after the change
does not exist inserted with customer_id: 999 and the body the new row
  • The inserted row is validated as a save : with a schema, every required field must be in the body.
  • Works on MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server and Oracle.
  • With returnDocument=before and an insert, the answer is null : there was no row before.
  • From code : g.sys.db.updateById({ ..., upsert: true }).