> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blinkops.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Redshift Data Execute Statement

Run a single SQL statement (DML or DDL) against an Amazon Redshift cluster or Serverless workgroup using the Redshift Data API.

The statement runs asynchronously - the action returns a statement `Id`, which the `Redshift Data Get Statement Result V2` action uses to fetch the rows. Set `Wait Time Seconds` to have the API wait (up to 30 seconds) for the statement to finish before responding.

Provide the target data warehouse and the authentication details as one of the following combinations:

* **Cluster + Secrets Manager** - `Cluster Identifier`, `Database` and `Secret ARN`.
* **Cluster + temporary credentials as an IAM identity** - `Cluster Identifier` and `Database`.
* **Cluster + temporary credentials as a database user** - `Cluster Identifier`, `Database` and `Database User`.
* **Serverless workgroup** - `Workgroup Name` and `Database`, optionally with `Secret ARN`.

<Note>
  External Documentation

  To learn more, visit the [AWS documentation](https://docs.aws.amazon.com/redshift-data/latest/APIReference/API_ExecuteStatement.html).
</Note>

## Basic Parameters

<div className="integrations-table">
  | Parameter          | Description                                                                                                                                                                                                                                                                    |
  | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
  | AWS Region         | The AWS Region of the Redshift cluster or Serverless workgroup.                                                                                                                                                                                                                |
  | Cluster Identifier | The identifier of the provisioned Redshift cluster to connect to.<br /><br />Required when connecting to a cluster. Leave empty when connecting to a Redshift Serverless workgroup.                                                                                            |
  | Database           | The name of the database to run the statement against.<br /><br />Can be obtained using the `Redshift Data List Databases` action.<br /><br />Required unless you are reusing an existing session via `Session ID`.                                                            |
  | Database User      | The database user name to connect as.<br /><br />Only relevant when connecting to a provisioned cluster as a database user using temporary credentials.                                                                                                                        |
  | Result Format      | Select the data format of the statement result. Defaults to `JSON`.<br /><br />**Note**: the `Redshift Data Get Statement Result V2` action can only fetch the results of statements that were run with `CSV`.                                                                 |
  | SQL Parameters     | The values for the named placeholders in the SQL statement, as a list of `name`/`value` objects.<br /><br />For example:<br /><pre><code>\[<br />  \{<br />    "name": "id",<br />    "value": "42"<br />  }<br />]</code></pre>                                               |
  | SQL Statement      | The SQL statement text to run. This must be a single SQL statement.<br /><br />To parameterize the statement, use named placeholders and supply their values in `SQL Parameters`. For example: `SELECT * FROM users WHERE id = :id`.                                           |
  | Secret ARN         | The name or ARN of the AWS Secrets Manager secret holding the `username` and `password` of the database user.<br /><br />Required when authenticating with Secrets Manager. Leave empty to authenticate with temporary credentials derived from the connection's IAM identity. |
  | Wait Time Seconds  | The number of seconds to wait for the SQL statement to finish before the API returns a response.<br /><br />Valid values range from `1` to `30`.                                                                                                                               |
  | Workgroup Name     | The Redshift Serverless workgroup name or ARN to connect to.<br /><br />Required when connecting to a serverless workgroup. Leave empty when connecting to a provisioned cluster.                                                                                              |
</div>

## Advanced Parameters

<div className="integrations-table">
  | Parameter                        | Description                                                                                                                                                                                                                                              |
  | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | Client Token                     | The unique, case-sensitive identifier (typically a UUID) used to ensure the idempotency of the request.                                                                                                                                                  |
  | Disable XML To JSON Auto Convert | When checked, XML responses are not automatically converted into JSON format.                                                                                                                                                                            |
  | Send Event To EventBridge        | Select to send an event to the Amazon EventBridge event bus after the SQL statement runs.                                                                                                                                                                |
  | Session ID                       | The identifier of an existing session to run the statement in.<br /><br />Can be obtained using the `Redshift Data Execute Statement` or `Redshift Data List Statements` action.<br /><br />Use this to run several statements against the same session. |
  | Session Keep Alive Seconds       | The number of seconds to keep the session alive after the statement finishes.<br /><br />Valid values range from `0` to `86400` (24 hours).                                                                                                              |
  | Statement Name                   | The name to give the SQL statement, used to identify the query later on.                                                                                                                                                                                 |
</div>

## Example Output

```json theme={"dark"}
{
	"ClusterIdentifier": "redshift-cluster-1",
	"CreatedAt": 1598323175.823,
	"Database": "dev",
	"DbUser": "IAM:user",
	"Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766",
	"SecretArn": "arn:aws:secretsmanager:us-east-1:123456789012:secret:redshift-1",
	"SessionId": "1e2f3a4b-5c6d-7e8f-9a0b-1c2d3e4f5a6b",
	"WorkgroupName": "default-workgroup"
}
```

## Workflow Library Example

[Redshift Data Execute Statement with Aws and Send Results Via Email](https://library.blinkops.com/workflows/redshift-data-execute-statement-with-aws-and-send-results-via-email)

<div className="iframe-wrapper">
  <div className="iframe-media">
    <img src="https://mintcdn.com/blinkops-2/ojHYuDeYX5FWuN8a/img/Icons/play-box.svg?fit=max&auto=format&n=ojHYuDeYX5FWuN8a&q=85&s=b8af968e71438a9499c3223c9bd29fb2" alt="Workflow Library" width="16" height="16" data-path="img/Icons/play-box.svg" />

    Preview this Workflow on desktop
  </div>

  <iframe className="iframe" src="https://library.blinkops.com/workflows/redshift-data-execute-statement-with-aws-and-send-results-via-email/canvas" />
</div>
