Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQL: how to check if keyspace exists?

Tags:

cassandra

cql

I need to check if certain keyspace exists in Cassandra database. I need to write smth like this:

if (keyspace KEYSPACE_NAME not exists) create keyspace KEYSPACE_NAME;

There's a command describe keyspace, but can I somehow retrieve information from it in cql script?

like image 666
Yury Pogrebnyak Avatar asked Mar 11 '12 15:03

Yury Pogrebnyak


People also ask

How do I check my Cassandra keyspace?

Go to data tab > there you will see all keyspcaces created by you and some system keyspaces. You can see all tables under individual keyspaces and also replicator factor for keyspace.

How do I find the keyspace replication factor in Cassandra?

If you want to look at the replication factor of a given keyspace, simply execute SELECT * FROM system_schema. keyspaces; and it will print all replication information you need.

How do I select a Keyspace in Cassandra?

To select a keyspace in Cassandra and perform actions on it, use the keyword USE . The CQL shell switches to the name of the keyspace you specified. To change the current keyspace, use the same command with another name. Note: Whenever you create a table in Cassandra, you start by defining the keyspace.

How would you describe Keyspace in Cassandra?

A keyspace is an object that is used to hold column families, user defined types. A keyspace is like RDBMS database which contains column families, indexes, user defined types, data center awareness, strategy used in keyspace, replication factor, etc. In Cassandra, "Create Keyspace" command is used to create keyspace.


1 Answers

Just providing fresh information. As of CQL3 while creating a keyspace you can add if statement like this

CREATE KEYSPACE IF NOT EXISTS Test
    WITH replication = {'class': 'SimpleStrategy',
                        'replication_factor' : 3}
like image 103
fgakk Avatar answered Oct 21 '22 23:10

fgakk