---
title: "Data manipulation"
description: "Create, read, change and delete records with the Mojo SDK using select(), create(), insert(), insert_relation(), update(), upsert(), merge(), patch() and delete()."
canonical_url: "https://surrealdb.com/docs/reference/mojo/concepts/data-manipulation"
sdk: "Mojo SDK"
surrealdb_version: "4.x"
last_modified: "2026-11-24T05:29:47Z"
---

> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Data manipulation

Create, read, change and delete records with the Mojo SDK using select(), create(), insert(), insert_relation(), update(), upsert(), merge(), patch() and delete().

The Mojo SDK wraps the most common record statements so you do not have to write the SurrealQL by hand. Each method takes the table or record to act on and, for methods that write, the data as a JSON string. The SDK builds the SurrealQL statement internally, and the description of each method states the statement it runs. Every method returns an `RpcResponse`, described under [Reading the response](/docs/reference/mojo/concepts/executing-queries.md#reading-the-response).

| Method | Description |
| --- | --- |
| [`client.select()`](#select) | Selects all records in a table, or a specific record |
| [`client.create()`](#create) | Creates a record in the database |
| [`client.insert()`](#insert) | Inserts one or more records into a table |
| [`client.insert_relation()`](#insert-relation) | Inserts one or more relation records into a table |
| [`client.update()`](#update) | Updates all records in a table, or a specific record, replacing their content |
| [`client.upsert()`](#upsert) | Creates a record if it does not exist, or updates it if it does |
| [`client.merge()`](#merge) | Merges data into all records in a table, or a specific record |
| [`client.patch()`](#patch) | Applies a JSON Patch to all records in a table, or a specific record |
| [`client.delete()`](#delete) | Deletes all records in a table, or a specific record |

## `.select()` {#select}

Selects all records in a table, or a specific record. This is a convenience wrapper that runs `SELECT * FROM <thing>;`.

```python title="Method Syntax"
client.select(thing, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `thing` | The table or specific record to select. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
# Select every record in a table
var people = client.select("person")

# Select a specific record
var chiru = client.select("person:chiru")
```

## `.create()` {#create}

Creates a record in the database. This is a convenience wrapper that runs `CREATE <thing> CONTENT <content_json>;`.

```python title="Method Syntax"
client.create(thing, content_json, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `thing` | The table or specific record to create. |
| `content_json` | The record content as a JSON string. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
var resp = client.create("person", '{ "name": "Chiru", "age": 30 }')
```

## `.insert()` {#insert}

Inserts one or more records into a table. This is a convenience wrapper that runs `INSERT INTO <table> <data_json>;`.

```python title="Method Syntax"
client.insert(table, data_json, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `table` | The table to insert into. |
| `data_json` | A single record or an array of records, as a JSON string. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
var resp = client.insert("person", '[{ "name": "Alice" }, { "name": "Bob" }]')
```

## `.insert_relation()` {#insert-relation}

Inserts one or more relation records into a table. This is a convenience wrapper that runs `INSERT RELATION INTO <table> <data_json>;`.

```python title="Method Syntax"
client.insert_relation(table, data_json, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `table` | The relation table to insert into. |
| `data_json` | A single relation or an array of relations, as a JSON string. Each carries an `in` and an `out` record. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
var resp = client.insert_relation(
    "likes",
    '[{ "in": "person:alice", "out": "person:bob" }]',
)
```

## `.update()` {#update}

Updates all records in a table, or a specific record, replacing their content. This is a convenience wrapper that runs `UPDATE <thing> CONTENT <content_json>;`.

```python title="Method Syntax"
client.update(thing, content_json, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `thing` | The table or specific record to update. |
| `content_json` | The replacement content as a JSON string. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
var resp = client.update("person:chiru", '{ "age": 31 }')
```

## `.upsert()` {#upsert}

Creates a record if it does not exist, or updates it if it does. This is a convenience wrapper that runs `UPSERT <thing> CONTENT <content_json>;`.

```python title="Method Syntax"
client.upsert(thing, content_json, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `thing` | The table or specific record to upsert. |
| `content_json` | The record content as a JSON string. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
var resp = client.upsert("person:chiru", '{ "name": "Chiru", "age": 31 }')
```

## `.merge()` {#merge}

Merges data into all records in a table, or a specific record, leaving unspecified fields untouched. This is a convenience wrapper that runs `UPDATE <thing> MERGE <data_json>;`.

```python title="Method Syntax"
client.merge(thing, data_json, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `thing` | The table or specific record to merge into. |
| `data_json` | The data to merge, as a JSON string. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
var resp = client.merge("person:chiru", '{ "age": 31 }')
```

## `.patch()` {#patch}

Applies a JSON Patch to all records in a table, or a specific record. This is a convenience wrapper that runs `UPDATE <thing> PATCH <patch_json>;`.

```python title="Method Syntax"
client.patch(thing, patch_json, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `thing` | The table or specific record to patch. |
| `patch_json` | A JSON Patch array as a JSON string. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
var resp = client.patch(
    "person:chiru",
    '[{ "op": "replace", "path": "/age", "value": 31 }]',
)
```

## `.delete()` {#delete}

Deletes all records in a table, or a specific record. This is a convenience wrapper that runs `DELETE <thing>;`.

```python title="Method Syntax"
client.delete(thing, session, txn)
```

### Arguments

| Argument | Description |
| --- | --- |
| `thing` | The table or specific record to delete. |
| `session` | An optional session id. |
| `txn` | An optional transaction id. |

### Example usage

```python
# Delete a specific record
var resp = client.delete("person:chiru")

# Delete every record in a table
var cleared = client.delete("person")
```
