Search code examples
cassandracql

select string literal in cassandra cql


I am new to Cassandra and I am trying to run a simple query in CQL:

select aggregate_name as name, 'test' as test from aggregates;

and I get an error: Line 1: no viable alternative at input ''test''

The question is: how could I select string literal in Apache Cassandra?


Solution

  • I found an ugly workaround, if you really want to print a text value as a column:

    cqlsh> select aggregate_name as name, blobAsText(textAsBlob('test')) as test from aggregates;
     name | test
    ------+------
     dude | test
    

    CQL supports native Cassandra functions as a select_expression, so you can convert your string literal to a blob and back again as shown above. (source)