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 Lightweight transactions
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/lightweight-transactions.md.

Lightweight transactionsΒΆ

Use ScanCAS or MapScanCAS for a conditional statement. Always inspect the returned applied value:

var currentVersion int
applied, err := session.Query(
	"UPDATE documents SET body = ?, version = ? WHERE id = ? IF version = ?",
	newBody,
	nextVersion,
	documentID,
	expectedVersion,
).ScanCAS(&currentVersion)
if err != nil {
	return err
}
if !applied {
	// Another writer changed the document.
}

Use ExecuteBatchCAS or MapExecuteBatchCAS for conditional batches. At least one statement must be conditional. Every statement, including unconditional statements, must target the same table and partition, and every condition must succeed for the batch to apply.

Both methods return an iterator after scanning the first result row. Always close a non-nil iterator, even when no additional rows are needed, and handle the error from Iter.Close so its page buffers and other resources are released.

Lightweight transactions use Paxos and cost more than ordinary reads and writes. Use them only when compare-and-set semantics are required.

Was this page helpful?

PREVIOUS
Batch statements
NEXT
Request timeouts
  • 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