0
votes

I am calling CQLSH queries via JAVA Code. The query being SELECT key,column1,column2,value,ttl(value) AS ttl FROM TABLE.

This works fine.

All the tables for which the query is fired has a column named value. But column2 is missing for some of the tables.

So to use the query above dynamically if i could write something like this it would be great. Select *,ttl(value) AS ttl from TABLE.

But looks like directly there is no option to do this. Am i missing anything? Or i will have to manually build query for each of my tables.

1

1 Answers

1
votes

You will need to build the query dynamically. There is no way we can select * and additional column. Please refer https://cassandra.apache.org/doc/latest/cql/dml.html for select query structure. It expects either "select_clause" or *, never both

select_statement ::=  SELECT [ JSON | DISTINCT ] ( select_clause | '*' )
                      FROM table_name
                      [ WHERE where_clause ]
                      [ GROUP BY group_by_clause ]
                      [ ORDER BY ordering_clause ]
                      [ PER PARTITION LIMIT (integer | bind_marker) ]
                      [ LIMIT (integer | bind_marker) ]
                      [ ALLOW FILTERING ]
select_clause    ::=  selector [ AS identifier ] ( ',' selector [ AS identifier ] )
selector         ::=  column_name
                      | term
                      | CAST '(' selector AS cql_type ')'
                      | function_name '(' [ selector ( ',' selector )* ] ')'
                      | COUNT '(' '*' ')'
where_clause     ::=  relation ( AND relation )*
relation         ::=  column_name operator term
                      '(' column_name ( ',' column_name )* ')' operator tuple_literal
                      TOKEN '(' column_name ( ',' column_name )* ')' operator term
operator         ::=  '=' | '<' | '>' | '<=' | '>=' | '!=' | IN | CONTAINS | CONTAINS KEY
group_by_clause  ::=  column_name ( ',' column_name )*
ordering_clause  ::=  column_name [ ASC | DESC ] ( ',' column_name [ ASC | DESC ] )*