How to create Cassandra columns having whitespace without double quotes?

Viewed 41

I am creating cassandra table, where some column can have white spaces like "Marks Obtained in %"

I can create table like below which works

CREATE TABLE test1 (Time text ,"Marks Obtained in %" text ,PRIMARY KEY (Time));

The issue is now for all my retrieve query, I have to supply column name inside double quotes else it will not work.

ex:

select "Marks Obtained in %" from test1

The column name itself becomes "Marks Obtained in %" with double quotes and not <Marks Obtained in %> without double quotes.

Since table creation is via python program, I need to maintain uniformity, while creating all the columns.

Is there any way in cassandra to make column names with white spaces, I saw in SQL something like below

CREATE TABLE IDE_Dump
(
   Name VARCHAR(255),
   [Head Name] VARCHAR(255),
   [Parent Account] VARCHAR(255) 
);
2 Answers

Unfortunately, it isn't possible to do specify a column name with spaces without enclosing them in quotes.

As a workaround, swap the spaces with underscores (_) like column_name. Cheers!

Another alternative approach is to use a column with the supported character limits and during the selection, use SELECT marks_in_perct AS "Marks Obtained in %" from keyspace_name.table_name WHERE ...; to achieve this.

Related