---
url: /process-functions/datasource-insert.md
description: Runs an INSERT statement against a datasource and returns the new row's key.
---

# datasource.insert&#x20;

Runs an INSERT statement against a datasource and returns the new row's key.

::: warning Deprecated
Use [`datasource.client(datasource).execute(statement, params)`](/process-functions/datasourceclient#execute) instead.
:::

```js
datasource.insert(datasource, query, parameters)
```

## Parameters

| Parameter | Type | Description |
|---|---|---|
| `datasource` | `string` | The datasource's name. It must be a JDBC datasource. |
| `query` | `string` | The INSERT statement. Use `?` placeholders for values. |
| `parameters` | `string[]` | Values for the `?` placeholders, in order. |

## Returns

The key generated for the new row, or `0` when there isn't one.

## Examples

```js
const id = datasource.insert("Internal Datastore", "INSERT INTO department_codes (department_id, department_name) VALUES (?, ?);", ["001", "Head Office"]);
```
