【问题标题】:select string literal in cassandra cql在cassandra cql中选择字符串文字
【发布时间】:2017-01-14 13:57:34
【问题描述】:

我是 Cassandra 的新手,我正在尝试在 CQL 中运行一个简单的查询:

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

我收到一个错误:第 1 行:输入“测试”时没有可行的替代方案

问题是:如何在 Apache Cassandra 中选择字符串文字?

【问题讨论】:

  • [将其添加为评论,因为我不是 100% 确定] 我认为 CQL 不支持这一点,可能最接近这一点的方法是创建一个 UDF...跨度>

标签: cassandra cql


【解决方案1】:

如果您真的想将文本值打印为列,我发现了一个丑陋的解决方法:

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

CQL 支持作为 select_expression 的原生 Cassandra 函数,因此您可以将字符串文字转换为 blob 并再次返回,如上所示。 (source)

【讨论】:

  • 不错!你说得对,这绝对是丑陋的,但我有点喜欢这种解决方法。
猜你喜欢
  • 2014-11-25
  • 2018-02-21
  • 2016-04-14
  • 2014-03-23
  • 1970-01-01
  • 2014-01-03
  • 2016-07-10
  • 1970-01-01
  • 2021-10-03
相关资源
最近更新 更多