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
Search Ask AI
ScyllaDB Docs ScyllaDB gocql driver Executing CQL statements Batch statements
For AI agents: a documentation index is available at https://gocql-driver.docs.scylladb.com/master/llms.txt. A Markdown version of this page is at https://gocql-driver.docs.scylladb.com/master/statements/batches.md.

Batch statementsΒΆ

Use batches for related DML statements. Prefer single-partition batches; multi-partition batches add coordinator work and network hops. Updates within one partition are atomic. Across partitions, a failed unlogged batch may be partly applied.

batch := session.Batch(gocql.UnloggedBatch).WithContext(ctx)
batch.Query(
	"INSERT INTO events (account_id, event_id, payload) VALUES (?, ?, ?)",
	accountID,
	firstEventID,
	firstPayload,
)
batch.Query(
	"INSERT INTO events (account_id, event_id, payload) VALUES (?, ?, ?)",
	accountID,
	secondEventID,
	secondPayload,
)

if err := session.ExecuteBatch(batch); err != nil {
	return err
}

Multi-partition logged batches use the batch log to ensure all mutations eventually complete or none do. They do not provide cross-partition isolation: concurrent readers may observe mutations to different partitions separately. Recovery completes outstanding mutations rather than rolling back applied ones. An error does not always prove that no mutation occurred. After a timeout or post-send transport error, a gocql.QueryError with PotentiallyExecuted() == true means the final outcome is unknown. Reconcile application state before retrying a non-idempotent batch.

Use logged batches when all-or-none completion across partitions is required, not as a general throughput optimization. Counter updates require gocql.CounterBatch.

For variable-length batches that repeatedly use the same statement, Session.ExecuteBatch prepares and caches individual statements more efficiently than sending a complete BEGIN BATCH ... APPLY BATCH string through Query.Exec.

Was this page helpful?

PREVIOUS
Paging
NEXT
Lightweight transactions
  • Create an issue
  • Edit this page
ScyllaDB gocql driver
Search Ask AI
  • master
    • master
  • Quick start
  • Connecting to the cluster
    • Compression
    • Authentication
    • TLS
    • Client routes (PrivateLink / Private Service Connect)
  • Executing CQL statements
    • Paging
    • Batch statements
    • Lightweight transactions
    • Request timeouts
  • Data types
  • Load balancing
  • Retry policy configuration
  • Speculative execution
Docs Tutorials University Contact Us About Us
© 2026 ScyllaDB | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 14 Sep 2026.
Powered by Sphinx 9.1.0 & ScyllaDB Theme 1.9.3