Check column existence
All columns
The DESCRIBE TABLE
command shows all the table information, including the column definitions.
For example, if a cycling.comments
table is defined, the following command returns the table definition:
DESCRIBE TABLE cycling.comments;
Results
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 = '99PERCENTILE'
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND nodesync = {'enabled': 'true', 'incremental': 'true'}
AND read_repair = 'BLOCKING'
AND speculative_retry = '99PERCENTILE';
One column
If a column exists, a SELECT
command will return any data stored in the column.
If your table has many rows, DataStax recommends that you limit the results with WHERE
clauses and other filters.
Unrestricted SELECT
statements can be resource intensive and time consuming for all but the smallest tables.
SELECT * FROM cycling.upcoming_calendar WHERE year = 2015 AND month = 6;
If the column exists, the query succeeds and returns results:
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)
If the column is a map
column, the results are in JSON format:
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)