Skip to content

batch_execute_statement

batch_execute_statement(
    sqls: SqlList,
    *,
    config_overrides: Optional[RedshiftDataClientConfig] = None,
    cluster_identifier: Optional[ClusterIdentifierString] = None,
    secret_arn: Optional[SecretArn] = None,
    db_user: Optional[String] = None,
    database: Optional[String] = None,
    with_event: Optional[bool] = None,
    statement_name: Optional[StatementNameString] = None,
    parameters: Optional[SqlParametersList] = None,
    workgroup_name: Optional[WorkgroupNameString] = None,
    client_token: Optional[ClientToken] = None,
    result_format: Optional[ResultFormatString] = None,
    session_keep_alive_seconds: Optional[SessionAliveSeconds] = None,
    session_id: Optional[UUID] = None,
    execution_mode: Optional[ExecutionMode] = None,
    wait_time_seconds: Optional[WaitTimeSeconds] = None,
) -> BatchExecuteStatementOutput

Runs one or more SQL statements, which can be data manipulation language (DML) or data definition language (DDL). Depending on the authorization method, use one of the following combinations of request parameters:

  • Secrets Manager - when connecting to a cluster, provide the secret-arn of a secret stored in Secrets Manager which has username and password. The specified secret contains credentials to connect to the database you specify. When you are connecting to a cluster, you also supply the database name, If you provide a cluster identifier (dbClusterIdentifier), it must match the cluster identifier stored in the secret. When you are connecting to a serverless workgroup, you also supply the database name.

  • Temporary credentials - when connecting to your data warehouse, choose one of the following options:

    • When connecting to a serverless workgroup, specify the workgroup name and database name. The database user name is derived from the IAM identity. For example, arn:iam::123456789012:user:foo has the database user name IAM:foo. Also, permission to call the redshift-serverless:GetCredentials operation is required.

    • When connecting to a cluster as an IAM identity, specify the cluster identifier and the database name. The database user name is derived from the IAM identity. For example, arn:iam::123456789012:user:foo has the database user name IAM:foo. Also, permission to call the redshift:GetClusterCredentialsWithIAM operation is required.

    • When connecting to a cluster as a database user, specify the cluster identifier, the database name, and the database user name. Also, permission to call the redshift:GetClusterCredentials operation is required.

For more information about the Amazon Redshift Data API and CLI usage examples, see Using the Amazon Redshift Data API in the Amazon Redshift Management Guide.

Parameters:

  • sqls (SqlList) –

    One or more SQL statements to run. The SQL statements run serially in the order of the array. Subsequent SQL statements don't start until the previous statement in the array completes. By default, the SQL statements are run as a single transaction. If any SQL statement fails, all work is rolled back. To change this behavior, see the ExecutionMode parameter.

  • cluster_identifier (Optional[ClusterIdentifierString], default: None ) –

    The cluster identifier. This parameter is required when connecting to a cluster and authenticating using either Secrets Manager or temporary credentials.

  • secret_arn (Optional[SecretArn], default: None ) –

    The name or ARN of the secret that enables access to the database. This parameter is required when authenticating using Secrets Manager.

  • db_user (Optional[String], default: None ) –

    The database user name. This parameter is required when connecting to a cluster as a database user and authenticating using temporary credentials.

  • database (Optional[String], default: None ) –

    The name of the database. This parameter is required when authenticating using either Secrets Manager or temporary credentials.

  • with_event (Optional[bool], default: None ) –

    A value that indicates whether to send an event to the Amazon EventBridge event bus after the SQL statements run.

  • statement_name (Optional[StatementNameString], default: None ) –

    The name of the SQL statements. You can name the SQL statements when you create them to identify the query.

  • parameters (Optional[SqlParametersList], default: None ) –

    The parameters for the SQL statements. The parameters are available to all SQL statements in the batch. Each statement can reference any subset of the provided parameters. Each provided parameter must be referenced by at least one SQL statement in the batch.

  • workgroup_name (Optional[WorkgroupNameString], default: None ) –

    The serverless workgroup name or Amazon Resource Name (ARN). This parameter is required when connecting to a serverless workgroup and authenticating using either Secrets Manager or temporary credentials.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier that you provide to ensure the idempotency of the request.

  • result_format (Optional[ResultFormatString], default: None ) –

    The data format of the result of the SQL statement. If no format is specified, the default is JSON.

  • session_keep_alive_seconds (Optional[SessionAliveSeconds], default: None ) –

    The number of seconds to keep the session alive after the query finishes. The maximum time a session can keep alive is 24 hours. After 24 hours, the session is forced closed and the query is terminated.

  • session_id (Optional[UUID], default: None ) –

    The session identifier of the query.

  • execution_mode (Optional[ExecutionMode], default: None ) –

    Determines how the SQL statements in the batch are run. If set to TRANSACTION (the default), all SQL statements are run as a single transaction and they are committed or rolled back together. If set to AUTO_COMMIT, each SQL statement is committed individually, and a failure of one statement does not affect the others.

  • wait_time_seconds (Optional[WaitTimeSeconds], default: None ) –

    The number of seconds to wait for all SQL statements in the batch to complete execution before returning the response. If the SQL statements do not complete within the specified time, the response returns the current status. The maximum value is 30 seconds.

Raises:

Source code in docs_src/capo_redshift_data/_services/redshift_data.py
def batch_execute_statement(
    self,
    sqls: "capo_redshift_data.types.sql_list.SqlList",
    *,
    config_overrides: Optional[RedshiftDataClientConfig] = None,
    cluster_identifier: Optional[
        "capo_redshift_data.types.cluster_identifier_string.ClusterIdentifierString"
    ] = None,
    secret_arn: Optional["capo_redshift_data.types.secret_arn.SecretArn"] = None,
    db_user: Optional["capo_redshift_data.types.string.String"] = None,
    database: Optional["capo_redshift_data.types.string.String"] = None,
    with_event: Optional[bool] = None,
    statement_name: Optional[
        "capo_redshift_data.types.statement_name_string.StatementNameString"
    ] = None,
    parameters: Optional[
        "capo_redshift_data.types.sql_parameters_list.SqlParametersList"
    ] = None,
    workgroup_name: Optional[
        "capo_redshift_data.types.workgroup_name_string.WorkgroupNameString"
    ] = None,
    client_token: Optional[
        "capo_redshift_data.types.client_token.ClientToken"
    ] = None,
    result_format: Optional[
        "capo_redshift_data.types.result_format_string.ResultFormatString"
    ] = None,
    session_keep_alive_seconds: Optional[
        "capo_redshift_data.types.session_alive_seconds.SessionAliveSeconds"
    ] = None,
    session_id: Optional["capo_redshift_data.types.uuid.UUID"] = None,
    execution_mode: Optional[
        "capo_redshift_data.types.execution_mode.ExecutionMode"
    ] = None,
    wait_time_seconds: Optional[
        "capo_redshift_data.types.wait_time_seconds.WaitTimeSeconds"
    ] = None,
) -> "capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput":
    """<p>Runs one or more SQL statements, which can be data manipulation language (DML) or data definition language (DDL). Depending on the authorization method, use one of the following combinations of request parameters: </p> <ul> <li> <p>Secrets Manager - when connecting to a cluster, provide the <code>secret-arn</code> of a secret stored in Secrets Manager which has <code>username</code> and <code>password</code>. The specified secret contains credentials to connect to the <code>database</code> you specify. When you are connecting to a cluster, you also supply the database name, If you provide a cluster identifier (<code>dbClusterIdentifier</code>), it must match the cluster identifier stored in the secret. When you are connecting to a serverless workgroup, you also supply the database name.</p> </li> <li> <p>Temporary credentials - when connecting to your data warehouse, choose one of the following options:</p> <ul> <li> <p>When connecting to a serverless workgroup, specify the workgroup name and database name. The database user name is derived from the IAM identity. For example, <code>arn:iam::123456789012:user:foo</code> has the database user name <code>IAM:foo</code>. Also, permission to call the <code>redshift-serverless:GetCredentials</code> operation is required.</p> </li> <li> <p>When connecting to a cluster as an IAM identity, specify the cluster identifier and the database name. The database user name is derived from the IAM identity. For example, <code>arn:iam::123456789012:user:foo</code> has the database user name <code>IAM:foo</code>. Also, permission to call the <code>redshift:GetClusterCredentialsWithIAM</code> operation is required.</p> </li> <li> <p>When connecting to a cluster as a database user, specify the cluster identifier, the database name, and the database user name. Also, permission to call the <code>redshift:GetClusterCredentials</code> operation is required.</p> </li> </ul> </li> </ul> <p>For more information about the Amazon Redshift Data API and CLI usage examples, see <a href="https://docs.aws.amazon.com/redshift/latest/mgmt/data-api.html">Using the Amazon Redshift Data API</a> in the <i>Amazon Redshift Management Guide</i>. </p>

    Args:
        sqls: <p>One or more SQL statements to run. The SQL statements run serially in the order of the array. Subsequent SQL statements don't start until the previous statement in the array completes. By default, the SQL statements are run as a single transaction. If any SQL statement fails, all work is rolled back. To change this behavior, see the <code>ExecutionMode</code> parameter.</p>
        cluster_identifier: <p>The cluster identifier. This parameter is required when connecting to a cluster and authenticating using either Secrets Manager or temporary credentials. </p>
        secret_arn: <p>The name or ARN of the secret that enables access to the database. This parameter is required when authenticating using Secrets Manager. </p>
        db_user: <p>The database user name. This parameter is required when connecting to a cluster as a database user and authenticating using temporary credentials. </p>
        database: <p>The name of the database. This parameter is required when authenticating using either Secrets Manager or temporary credentials. </p>
        with_event: <p>A value that indicates whether to send an event to the Amazon EventBridge event bus after the SQL statements run. </p>
        statement_name: <p>The name of the SQL statements. You can name the SQL statements when you create them to identify the query. </p>
        parameters: <p>The parameters for the SQL statements. The parameters are available to all SQL statements in the batch. Each statement can reference any subset of the provided parameters. Each provided parameter must be referenced by at least one SQL statement in the batch.</p>
        workgroup_name: <p>The serverless workgroup name or Amazon Resource Name (ARN). This parameter is required when connecting to a serverless workgroup and authenticating using either Secrets Manager or temporary credentials.</p>
        client_token: <p>A unique, case-sensitive identifier that you provide to ensure the idempotency of the request.</p>
        result_format: <p>The data format of the result of the SQL statement. If no format is specified, the default is JSON.</p>
        session_keep_alive_seconds: <p>The number of seconds to keep the session alive after the query finishes. The maximum time a session can keep alive is 24 hours. After 24 hours, the session is forced closed and the query is terminated.</p>
        session_id: <p>The session identifier of the query.</p>
        execution_mode: <p>Determines how the SQL statements in the batch are run. If set to <code>TRANSACTION</code> (the default), all SQL statements are run as a single transaction and they are committed or rolled back together. If set to <code>AUTO_COMMIT</code>, each SQL statement is committed individually, and a failure of one statement does not affect the others.</p>
        wait_time_seconds: <p>The number of seconds to wait for all SQL statements in the batch to complete execution before returning the response. If the SQL statements do not complete within the specified time, the response returns the current status. The maximum value is 30 seconds.</p>

    Raises:
        capo_redshift_data.errors.active_sessions_exceeded_exception.ActiveSessionsExceededException: <p>The Amazon Redshift Data API operation failed because the maximum number of active sessions exceeded.</p>
        capo_redshift_data.errors.active_statements_exceeded_exception.ActiveStatementsExceededException: <p>The number of active statements exceeds the limit.</p>
        capo_redshift_data.errors.batch_execute_statement_exception.BatchExecuteStatementException: <p>An SQL statement encountered an environmental error while running.</p>
        capo_redshift_data.errors.internal_server_exception.InternalServerException: <p>The Amazon Redshift Data API operation failed due to invalid input. </p>
        capo_redshift_data.errors.resource_not_found_exception.ResourceNotFoundException: <p>The Amazon Redshift Data API operation failed due to a missing resource. </p>
        capo_redshift_data.errors.validation_exception.ValidationException: <p>The Amazon Redshift Data API operation failed due to invalid input. </p>
        capo_redshift_data.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_redshift_data.types.batch_execute_statement_input.BatchExecuteStatementInput]",
    ) -> OperationResponse[
        "capo_redshift_data.types.batch_execute_statement_output.BatchExecuteStatementOutput"
    ]:
        import capo_redshift_data._operations.redshift_data.batch_execute_statement

        output, http_response = (
            capo_redshift_data._operations.redshift_data.batch_execute_statement.batch_execute_statement(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("BatchExecuteStatement")
    )
    input_: capo_redshift_data.types.batch_execute_statement_input.BatchExecuteStatementInput = {
        "sqls": sqls
    }
    if cluster_identifier is not None:
        input_["cluster_identifier"] = cluster_identifier
    if secret_arn is not None:
        input_["secret_arn"] = secret_arn
    if db_user is not None:
        input_["db_user"] = db_user
    if database is not None:
        input_["database"] = database
    if with_event is not None:
        input_["with_event"] = with_event
    if statement_name is not None:
        input_["statement_name"] = statement_name
    if parameters is not None:
        input_["parameters"] = parameters
    if workgroup_name is not None:
        input_["workgroup_name"] = workgroup_name
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if result_format is not None:
        input_["result_format"] = result_format
    if session_keep_alive_seconds is not None:
        input_["session_keep_alive_seconds"] = session_keep_alive_seconds
    if session_id is not None:
        input_["session_id"] = session_id
    if execution_mode is not None:
        input_["execution_mode"] = execution_mode
    if wait_time_seconds is not None:
        input_["wait_time_seconds"] = wait_time_seconds

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output