Andy Salnikov created CASSANDRA-20559:
-----------------------------------------
Summary: CQL syntax for constants in select clause.
Key: CASSANDRA-20559
URL: https://issues.apache.org/jira/browse/CASSANDRA-20559
Project: Apache Cassandra
Issue Type: Bug
Components: CQL/Syntax
Reporter: Andy Salnikov
I wanted to write a query that returns a literal {{NULL}} for a column, so I
tried the query like this:
{noformat}
cqlsh:db> select a, b, NULL from table;
{noformat}
but that returns an error:
{noformat}
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot
infer type for term NULL in selection clause (try using a cast to force a type)"
{noformat}
Same error happens for integer constant:
{noformat}
cqlsh:db> select a, b, 100 from table;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot
infer type for term 100 in selection clause (try using a cast to force a type)"
{noformat}
Adding {{CAST}} as suggested by the message does not help:
{noformat}
cqlsh:db> select a, b, CAST(100 as INT) from table;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot
infer type for term 100 in selection clause (try using a cast to force a type)"
{noformat}
I think that according to the
[docs|https://cassandra.apache.org/doc/latest/cassandra/developing/cql/dml.html#select-statement]
all of the above should work, the syntax is described as
{noformat}
select_clause::= `selector` [ AS `identifier` ] ( ',' `selector` [ AS
`identifier` ] )
selector::== `column_name`
| `term`
| CAST '(' `selector` AS `cql_type` ')'
{noformat}
And term is described on another
[page|https://cassandra.apache.org/doc/latest/cassandra/developing/cql/definitions.html#terms]
can be a constant or literal (among other things).
On Slack it was suggested that different cast syntax would work in this case:
{noformat}
cqlsh:db> select a, b, (int) 100 from table;
cqlsh:db> select a, b, (int) NULL from table;
{noformat}
and it works indeed (and this is probably what the error message suggests) but
it is not obvious from documentation that this indeed is needed or supported.
It would be nice to either fix the syntax to follow documentation, or update
documentation to reflect that that kind of cast is necessary.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]