The INSERT action executes an SQL INSERT statement against a database.
Use this action to create new records in a database. Query parameters can be passed separately from the SQL statement using metadata values, allowing data from forms, process variables, and integrations to be inserted into database tables. Database queries are executed using prepared statements to support secure parameter handling.
The input parameters of the action are:
| Parameter | Type | Required | Description |
|---|---|---|---|
| query | String | Required | The SQL INSERT statement to execute against the database. |
| metadata | JSON | Optional | A list of parameters that can be passed into the SQL statement. |
The metadata parameter can be used to pass process variables into the SQL statement. If the example metadata is:
{
"customerId": "CUST-10025",
"customerName": "Contoso Ltd",
"email": "contact@contoso.com"
}
It can be used for the following query:
INSERT INTO customers (
customer_id,
customer_name,
email_address
)
VALUES (
{customerId},
{customerName},
{email}
);
In this example, the values contained in metadata are substituted into the query as prepared statement parameters when the SQL statement is executed.
The output parameters from an insert statement are:
| Parameter | Type | Required | Description |
|---|---|---|---|
| result | Integer | Optional | The number of database rows affected by the INSERT statement. For example, a value of 1 indicates that one row was inserted successfully, while a value of 0 indicates that no rows were inserted. |