# Upsert Table Row Tool

Update an existing row or insert a new schema-valid row.

## When to Use

Use this tool when a record may already exist. `id` is required. The row updates if it exists, otherwise it inserts with that `id`. Supplied fields must match the table schema.

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `table_id` | string | Yes | The table's id or slug, as `list_tables` gives them; the slug aliases the id and either is accepted |
| `data` | object | Yes | Row data. Must include `id`. Fields must match the current schema. |

## Returns

| Field | Type | Description |
|-------|------|-------------|
| `success` | boolean | Whether the operation succeeded |
| `row_id` | string \| number | Row identifier; type follows table `id_format` |
| `operation` | string | `inserted` or `updated` |
| `table_id` | string | The table identifier |

## Example

```json
{
  "table_id": "customers",
  "data": {
    "id": "01HJK2N3M4P5Q6R7S8T9UVWXY",
    "name": "Updated Corp",
    "plan": "enterprise"
  }
}
```

## Notes

- `id` is required.
- If the row exists, it updates. If not, it inserts with that same `id`.
- Row writes do not add, rename, or widen columns.
- Modify schema before writing fields that are not already declared.
