Check column existence

Using cqlsh, you can either get the description of all columns and their data types, or discover whether a particular column exists in a table by querying the column’s data.

All columns

The CQLSH command DESCRIBE TABLE shows all the table information, including the columns defined. For example, if the cycling.comments table is defined, the following will return the table definition:

DESCRIBE TABLE cycling.comments;
Results
WARNING: cqlsh was built against 5.0-beta1, but this server is 5.0.  All features may not work!

CREATE TABLE cycling.comments (
    id uuid,
    created_at timestamp,
    comment text,
    commenter text,
    record_id timeuuid,
    PRIMARY KEY (id, created_at)
) WITH CLUSTERING ORDER BY (created_at DESC)
    AND additional_write_policy = '99p'
    AND allow_auto_snapshot = true
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND cdc = false
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.UnifiedCompactionStrategy', 'max_sstables_to_compact': '64', 'min_sstable_size': '100MiB', 'scaling_parameters': 'T4', 'sstable_growth': '0.3333333333333333', 'target_sstable_size': '1GiB'}
    AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND memtable = 'default'
    AND crc_check_chance = 1.0
    AND default_time_to_live = 0
    AND extensions = {}
    AND gc_grace_seconds = 864000
    AND incremental_backups = true
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair = 'BLOCKING'
    AND speculative_retry = '99p';

Particular column

If a column exists, a SELECT command will return any data stored in the column:

SELECT * FROM cycling.upcoming_calendar WHERE year = 2015 AND month = 6;
Results
WARNING: cqlsh was built against 5.0-beta1, but this server is 5.0.  All features may not work!

 year | month | description                                                                  | events
------+-------+------------------------------------------------------------------------------+----------------------------------------------------------------------------
 2015 |     6 | {'Criterium du Dauphine': 'Easy race', 'Tour du Suisse': 'Hard uphill race'} | ['Tour de France', 'Criterium du Dauphine', 'Vuelta Ciclista a Venezuela']

(1 rows)

See also:

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com