ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Deployments
    • Cloud
    • Server
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
    • Supported Driver Versions
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Install
Ask AI
ScyllaDB Docs ScyllaDB CPP RS Driver Using the Driver Batches

Caution

You're viewing documentation for an unstable version of ScyllaDB CPP RS Driver. Switch to the latest stable version.

BatchesΒΆ

Batches can be used to group multiple mutations (UPDATE, INSERT, DELETE) together into a single statement; simple or prepared. There are three different types of batches.

  • CASS_BATCH_TYPE_LOGGED is used to make sure that multiple mutations across multiple partitions happen atomically, that is, all the included mutations will eventually succeed. However, there is a performance penalty imposed by atomicity guarantee.

  • CASS_BATCH_TYPE_UNLOGGED is generally used to group mutations for a single partition and do not suffer from the performance penalty imposed by logged batches, but there is no atomicity guarantee for multi-partition updates.

  • CASS_BATCH_TYPE_COUNTER is used to group counters updates.

Important: Be careful when using batches as a performance optimization.

void execute_batch(CassSession* session) {
  /* This logged batch will make sure that all the mutations eventually succeed */
  CassBatch* batch = cass_batch_new(CASS_BATCH_TYPE_LOGGED);

  /* Statements can be immediately freed after being added to the batch */

  {
    CassStatement* statement
      = cass_statement_new("INSERT INTO example1(key, value) VALUES ('a', '1')", 0);
    cass_batch_add_statement(batch, statement);
    cass_statement_free(statement);
  }

  {
    CassStatement* statement
      = cass_statement_new("UPDATE example2 set value = '2' WHERE key = 'b'", 0);
    cass_batch_add_statement(batch, statement);
    cass_statement_free(statement);
  }

  {
    CassStatement* statement
      = cass_statement_new("DELETE FROM example3 WHERE key = 'c'", 0);
    cass_batch_add_statement(batch, statement);
    cass_statement_free(statement);
  }

  CassFuture* batch_future = cass_session_execute_batch(session, batch);

  /* Batch objects can be freed immediately after being executed */
  cass_batch_free(batch);

  /* This will block until the query has finished */
  CassError rc = cass_future_error_code(batch_future);

  printf("Batch result: %s\n", cass_error_desc(rc));

  cass_future_free(batch_future);
}

Was this page helpful?

PREVIOUS
Using the Driver
NEXT
Binding Parameters
  • Create an issue
  • Edit this page
ScyllaDB CPP RS Driver
  • master
    • master
    • v1.0.0
  • ScyllaDB CPP RS Driver
  • API Documentation
    • BasicTypes
    • CassConsistency
    • CassError
    • CassValueType
    • CustomAllocator
    • Logging
    • Miscellaneous
    • CassAggregateMeta
    • CassAuthenticator
    • CassAuthenticatorCallbacks
    • CassBatch
    • CassCluster
    • CassCollection
    • CassColumnMeta
    • CassCustomPayload
    • CassDataType
    • CassErrorResult
    • CassExecProfile
    • CassFunctionMeta
    • CassFuture
    • CassIndexMeta
    • CassInet
    • CassIterator
    • CassKeyspaceMeta
    • CassMaterializedViewMeta
    • CassMetrics
    • CassNode
    • CassPrepared
    • CassResult
    • CassRetryPolicy
    • CassRow
    • CassSchemaMeta
    • CassSession
    • CassSpeculativeExecutionMetrics
    • CassSsl
    • CassStatement
    • CassTableMeta
    • CassTimestampGen
    • CassTuple
    • CassUserType
    • CassUuid
    • CassUuidGen
    • CassValue
    • CassVersion
  • Getting Started
  • Architecture Overview
  • Installation
  • Building
  • Testing
  • Using the Driver
    • Batches
    • Binding Parameters
    • Client-side timestamps
    • Consistency
    • Data Types
      • The date and time Types
      • Tuples
      • User-Defined Types (UDTs)
      • UUIDs
    • Futures
    • Handling Results
    • Keyspaces
    • Prepared Statements
    • Schema Metadata
  • Configuration
    • Load balancing
    • Retry policies
    • Speculative Execution
    • Connection
    • Execution Profiles
    • Performance Tips
    • Client Configuration
  • Security
    • Authentication
    • TLS
  • Observability
    • Logging
    • Tracing
    • Metrics
Docs Tutorials University Contact Us About Us
© 2026, ScyllaDB. All rights reserved. | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 17 Mar 2026.
Powered by Sphinx 9.1.0 & ScyllaDB Theme 1.9.1
Ask AI