Search code examples
cassandracqlcql3

Cassandra: get column names of a columnfamily?


I'm wondering if there is a query in CQL3 that allows you to get column names of a specific columnfamily that has a static schema?
Thanks in advance :)


Solution

  • You could use the system keyspace to do this:

    SELECT column_name FROM system.schema_columnfamilies 
      WHERE keyspace_name = 'testks' AND columnfamily_name = 'testcf';
    

    Output in cqlsh (using cql3):

     column_name
    -------------
        password
    

    You can work out the key for the column by using:

    SELECT key_aliases FROM system.schema_columnfamilies WHERE keyspace_name='testks' 
    AND columnfamily_name='testcf';
    

    Output:

     key_aliases
    --------------
     ["username"]