Skip to content

batch_execute_statement async

batch_execute_statement(
    resource_arn: Arn,
    secret_arn: Arn,
    sql: SqlStatement,
    *,
    config_overrides: Optional[AsyncRDSDataClientConfig] = None,
    database: Optional[DbName] = None,
    schema: Optional[DbName] = None,
    parameter_sets: Optional[SqlParameterSets] = None,
    transaction_id: Optional[Id] = None,
) -> BatchExecuteStatementResponse

Runs a batch SQL statement over an array of data.

You can run bulk update and insert operations for multiple records using a DML statement with different parameter sets. Bulk operations can provide a significant performance improvement over individual insert and update operations.

If a call isn't part of a transaction because it doesn't include the transactionID parameter, changes that result from the call are committed automatically.

There isn't a fixed upper limit on the number of parameter sets. However, the maximum size of the HTTP request submitted through the Data API is 4 MiB. If the request exceeds this limit, the Data API returns an error and doesn't process the request. This 4-MiB limit includes the size of the HTTP headers and the JSON notation in the request. Thus, the number of parameter sets that you can include depends on a combination of factors, such as the size of the SQL statement and the size of each parameter set.

The response size limit is 1 MiB. If the call returns more than 1 MiB of response data, the call is terminated.

Parameters:

  • resource_arn (Arn) –

    The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.

  • secret_arn (Arn) –

    The ARN of the secret that enables access to the DB cluster. Enter the database user name and password for the credentials in the secret.

    For information about creating the secret, see Create a database secret.

  • sql (SqlStatement) –

    The SQL statement to run. Don't include a semicolon (;) at the end of the SQL statement.

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

    The name of the database.

  • schema (Optional[DbName], default: None ) –

    The name of the database schema.

    Currently, the schema parameter isn't supported.

  • parameter_sets (Optional[SqlParameterSets], default: None ) –

    The parameter set for the batch operation.

    The SQL statement is executed as many times as the number of parameter sets provided. To execute a SQL statement with no parameters, use one of the following options:

    • Specify one or more empty parameter sets.

    • Use the ExecuteStatement operation instead of the BatchExecuteStatement operation.

    Array parameters are not supported.

  • transaction_id (Optional[Id], default: None ) –

    The identifier of a transaction that was started by using the BeginTransaction operation. Specify the transaction ID of the transaction that you want to include the SQL statement in.

    If the SQL statement is not part of a transaction, don't set this parameter.

Raises:

Source code in docs_src/capo_rds_data/_services/async_rds_data.py
async def batch_execute_statement(
    self,
    resource_arn: "capo_rds_data.types.arn.Arn",
    secret_arn: "capo_rds_data.types.arn.Arn",
    sql: "capo_rds_data.types.sql_statement.SqlStatement",
    *,
    config_overrides: Optional[AsyncRDSDataClientConfig] = None,
    database: Optional["capo_rds_data.types.db_name.DbName"] = None,
    schema: Optional["capo_rds_data.types.db_name.DbName"] = None,
    parameter_sets: Optional[
        "capo_rds_data.types.sql_parameter_sets.SqlParameterSets"
    ] = None,
    transaction_id: Optional["capo_rds_data.types.id.Id"] = None,
) -> "capo_rds_data.types.batch_execute_statement_response.BatchExecuteStatementResponse":
    """<p>Runs a batch SQL statement over an array of data.</p> <p>You can run bulk update and insert operations for multiple records using a DML statement with different parameter sets. Bulk operations can provide a significant performance improvement over individual insert and update operations.</p> <note> <p>If a call isn't part of a transaction because it doesn't include the <code>transactionID</code> parameter, changes that result from the call are committed automatically.</p> <p>There isn't a fixed upper limit on the number of parameter sets. However, the maximum size of the HTTP request submitted through the Data API is 4 MiB. If the request exceeds this limit, the Data API returns an error and doesn't process the request. This 4-MiB limit includes the size of the HTTP headers and the JSON notation in the request. Thus, the number of parameter sets that you can include depends on a combination of factors, such as the size of the SQL statement and the size of each parameter set.</p> <p>The response size limit is 1 MiB. If the call returns more than 1 MiB of response data, the call is terminated.</p> </note>

    Args:
        resource_arn: <p>The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.</p>
        secret_arn: <p>The ARN of the secret that enables access to the DB cluster. Enter the database user name and password for the credentials in the secret.</p> <p>For information about creating the secret, see <a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/create_database_secret.html">Create a database secret</a>.</p>
        sql: <p>The SQL statement to run. Don't include a semicolon (;) at the end of the SQL statement.</p>
        database: <p>The name of the database.</p>
        schema: <p>The name of the database schema.</p> <note> <p>Currently, the <code>schema</code> parameter isn't supported.</p> </note>
        parameter_sets: <p>The parameter set for the batch operation.</p> <p>The SQL statement is executed as many times as the number of parameter sets provided. To execute a SQL statement with no parameters, use one of the following options:</p> <ul> <li> <p>Specify one or more empty parameter sets.</p> </li> <li> <p>Use the <code>ExecuteStatement</code> operation instead of the <code>BatchExecuteStatement</code> operation.</p> </li> </ul> <note> <p>Array parameters are not supported.</p> </note>
        transaction_id: <p>The identifier of a transaction that was started by using the <code>BeginTransaction</code> operation. Specify the transaction ID of the transaction that you want to include the SQL statement in.</p> <p>If the SQL statement is not part of a transaction, don't set this parameter.</p>

    Raises:
        capo_rds_data.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this action.</p>
        capo_rds_data.errors.bad_request_exception.BadRequestException: <p>There is an error in the call or in a SQL statement. This exception is deprecated.</p>
        capo_rds_data.errors.database_error_exception.DatabaseErrorException: <p>There was an error in processing the SQL statement.</p>
        capo_rds_data.errors.database_not_found_exception.DatabaseNotFoundException: <p>The DB cluster doesn't have a DB instance.</p>
        capo_rds_data.errors.database_resuming_exception.DatabaseResumingException: <p>A request was cancelled because the Aurora Serverless DB instance was paused. The Data API request automatically resumes the DB instance. Wait a few seconds and try again.</p>
        capo_rds_data.errors.database_unavailable_exception.DatabaseUnavailableException: <p>The writer instance in the DB cluster isn't available.</p>
        capo_rds_data.errors.forbidden_exception.ForbiddenException: <p>There are insufficient privileges to make the call.</p>
        capo_rds_data.errors.http_endpoint_not_enabled_exception.HttpEndpointNotEnabledException: <p>The HTTP endpoint for using RDS Data API isn't enabled for the DB cluster.</p>
        capo_rds_data.errors.internal_server_error_exception.InternalServerErrorException: <p>An internal error occurred.</p>
        capo_rds_data.errors.invalid_resource_state_exception.InvalidResourceStateException: <p>The resource is in an invalid state.</p>
        capo_rds_data.errors.invalid_secret_exception.InvalidSecretException: <p>The Secrets Manager secret used with the request isn't valid.</p>
        capo_rds_data.errors.secrets_error_exception.SecretsErrorException: <p>There was a problem with the Secrets Manager secret used with the request, caused by one of the following conditions:</p> <ul> <li> <p>RDS Data API timed out retrieving the secret.</p> </li> <li> <p>The secret provided wasn't found.</p> </li> <li> <p>The secret couldn't be decrypted.</p> </li> </ul>
        capo_rds_data.errors.service_unavailable_error.ServiceUnavailableError: <p>The service specified by the <code>resourceArn</code> parameter isn't available.</p>
        capo_rds_data.errors.statement_timeout_exception.StatementTimeoutException: <p>The execution of the SQL statement timed out.</p>
        capo_rds_data.errors.transaction_not_found_exception.TransactionNotFoundException: <p>The transaction ID wasn't found.</p>
        capo_rds_data.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_rds_data.types.batch_execute_statement_request.BatchExecuteStatementRequest]",
    ) -> AsyncOperationResponse[
        "capo_rds_data.types.batch_execute_statement_response.BatchExecuteStatementResponse"
    ]:
        import capo_rds_data._operations.rds_data_service.batch_execute_statement

        (
            output,
            http_response,
        ) = await capo_rds_data._operations.rds_data_service.batch_execute_statement.async_batch_execute_statement(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("BatchExecuteStatement")
    )
    input_: capo_rds_data.types.batch_execute_statement_request.BatchExecuteStatementRequest = {
        "resource_arn": resource_arn,
        "secret_arn": secret_arn,
        "sql": sql,
    }
    if database is not None:
        input_["database"] = database
    if schema is not None:
        input_["schema"] = schema
    if parameter_sets is not None:
        input_["parameter_sets"] = parameter_sets
    if transaction_id is not None:
        input_["transaction_id"] = transaction_id

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output