ScyllaDB Documentation Logo Documentation
  • Server
    • ScyllaDB Open Source
    • ScyllaDB Enterprise
    • ScyllaDB Alternator
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
Download
Menu
ScyllaDB Docs Scylla Rust Driver Making queries USE keyspace

USE keyspace¶

Using a keyspace allows to omit keyspace name in queries.

For example in cqlsh one could write:

cqlsh> SELECT * FROM my_keyspace.table;

 a     | b     |
-------+-------+
 12345 | 54321 |

(1 rows)
cqlsh> USE my_keyspace;
cqlsh:my_keyspace> SELECT * FROM table;

 a     | b     |
-------+-------+
 12345 | 54321 |

(1 rows)

Tables from other keyspaces can still easily be accessed by using their keyspace names.

cqlsh:my_keyspace> SELECT * FROM other_keyspace.other_table;

In the driver this can be achieved using Session::use_keyspace:

session
    .query("INSERT INTO my_keyspace.tab (a) VALUES ('test1')", &[])
    .await?;

session.use_keyspace("my_keyspace", false).await?;

// Now we can omit keyspace name in the query
session
    .query("INSERT INTO tab (a) VALUES ('test2')", &[])
    .await?;

The first argument is the keyspace name.
The second argument states whether this name is case sensitive.

It is also possible to send raw use keyspace query using Session::query instead of Session::use_keyspace such as:

session.query("USE my_keyspace", &[]).await?;

This method has a slightly worse latency than Session::use_keyspace - there are two roundtrips needed instead of one. Therefore, Session::use_keyspace is the preferred method for setting keyspaces.

Multiple use queries at once¶

Don’t run multiple use_keyspace queries at once. This could end up with half of connections using one keyspace and the other half using the other.

Case sensitivity¶

In CQL a keyspace name can be case insensitive (without ") or case sensitive (with ").
If the second argument to use_keyspace is set to true this keyspace name will be wrapped in ".
It is best to avoid the problem altogether and just not create two keyspaces with the same name but different cases.

Let’s see what happens when there are two keyspaces with the same name but different cases: my_keyspace and MY_KEYSPACE:

// lowercase name without case sensitivity will use my_keyspace
session.use_keyspace("my_keyspace", false).await?;

// lowercase name with case sensitivity will use my_keyspace
session.use_keyspace("my_keyspace", true).await?;

// uppercase name without case sensitivity will use my_keyspace
session.use_keyspace("MY_KEYSPACE", false).await?;

// uppercase name with case sensitivity will use MY_KEYSPACE
session.use_keyspace("MY_KEYSPACE", true).await?;
PREVIOUS
Paged query
NEXT
Schema agreement
Scylla Rust Driver
  • main
    • main
  • Scylla Rust Driver
  • Quick Start
    • Creating a project
    • Connecting and running a simple query
    • Running Scylla using Docker
  • Connecting to the cluster
    • Compression
    • Authentication
    • TLS
  • Making queries
    • Simple query
    • Query values
    • Query result
    • Prepared query
    • Batch statement
    • Paged query
    • USE keyspace
    • Schema agreement
    • Lightweight transaction (LWT) query
    • Query timeouts
  • Execution profiles
    • Creating a profile and setting it
    • All options supported by a profile
    • Priorities of execution settings
    • Remapping execution profile handles
  • Data Types
    • Bool, Tinyint, Smallint, Int, Bigint, Float, Double
    • Ascii, Text, Varchar
    • Counter
    • Blob
    • Inet
    • Uuid, Timeuuid
    • Date
    • Time
    • Timestamp
    • Duration
    • Decimal
    • Varint
    • List, Set, Map
    • Tuple
    • User defined types
  • Load balancing
    • DefaultPolicy
  • Retry policy configuration
    • Fallthrough retry policy
    • Default retry policy
    • Downgrading consistency retry policy
  • Speculative execution
    • Simple speculative execution
    • Percentile speculative execution
  • Driver metrics
  • Logging
  • Query tracing
    • Tracing a simple/prepared/batch query
    • Tracing a paged query
    • Tracing Session::prepare
    • Query Execution History
  • Schema
  • Create an issue
  • Edit this page

On this page

  • USE keyspace
    • Multiple use queries at once
    • Case sensitivity
Logo
Docs Contact Us About Us
Mail List Icon Slack Icon Forum Icon
© 2023, ScyllaDB. All rights reserved.
Last updated on 22 March 2023.
Powered by Sphinx 4.3.2 & ScyllaDB Theme 1.3.5