# insert_relation

The insert_relation() method for the SurrealDB Mojo SDK inserts one or more relations into a table.

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

<table>
    <thead>
        <tr>
            <th colspan="2" scope="col">Argument</th>
            <th colspan="2" scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>table</code></td>
            <td colspan="2" scope="row" data-label="Description">The relation table to insert into.</td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>data_json</code></td>
            <td colspan="2" scope="row" data-label="Description">A single relation or an array of relations, as a JSON string. Each carries an <code>in</code> and an <code>out</code> record.</td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>session</code></td>
            <td colspan="2" scope="row" data-label="Description">An optional session id.</td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>txn</code></td>
            <td colspan="2" scope="row" data-label="Description">An optional transaction id.</td>
        </tr>
    </tbody>
</table>

## Example usage

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

## Translated query

```surql
INSERT RELATION INTO $table $data_json;
```
