【问题标题】:cqlsh having issue executing using cqlsh -ecqlsh 使用 cqlsh -e 执行时出现问题
【发布时间】:2017-10-16 07:25:10
【问题描述】:

我很难使用 -e 选项执行,列名用引号括起来。

我想使用 unix 级别执行以下操作。试图从 shell 脚本运行。当我尝试将我的值放在引号中时,它会取消我专栏的引号。

select * from keyspace.cf where "columnname"=''

试过这个:

cqlsh hostname -e "select * from keyspace.cf where "columnname"=''"

它执行为 cqlsh hostname -e 'select * from keyspace.cf where columnname='

stdin>:1:InvalidRequest: Error from server: code=2200 [Invalid query] message="Undefined name columnaname in where clause ('columnname= 'value'')"

【问题讨论】:

  • 为什么要用引号括起来列名?你的表架构是什么?
  • cqlsh hostname -e "select * from keyspace.cf where columnname='' "... 列名不需要双引号(除非列名是大写字母)

标签: shell cassandra cqlsh


【解决方案1】:

你不需要在columnname周围加上引号,你只需要设置它并在它前面加上一个$。

cqlsh -u cassandra -p cassandra -e "SELECT $COLUMN FROm $KEYSPACE.$TABLE;"

这是我编写的名为 getVersion.sh 的脚本的摘录。

#!/bin/bash

KEYSPACE="system"
TABLE="local"
COLUMN="release_version"

~/local/apache-cassandra-3.10/bin/cqlsh -u cassandra -p cassandra -e "SELECT $COLUMN FROm $KEYSPACE.$TABLE;"

aploetz@dockingBay94:~/scripts$ ./getVersion.sh 

 release_version
-----------------
            3.10

(1 rows)

如果您的列名包含引号,同样会起作用。只要确保在您的变量定义中转义它们。这是一个类似的脚本,但它查询"columnName" TEXT 列:

#!/bin/bash

KEYSPACE="stackoverflow"
TABLE="stuff_with_quotes"
COLUMN="\"columnName\""

~/local/apache-cassandra-3.10/bin/cqlsh -u cassandra -p cassandra -e "SELECT $COLUMN FROm $KEYSPACE.$TABLE;"

【讨论】:

    猜你喜欢
    • 2016-06-30
    • 2016-07-21
    • 2014-08-01
    • 2018-04-27
    • 2018-06-09
    • 2015-05-26
    • 2016-01-09
    • 2017-07-26
    • 2019-10-23
    相关资源
    最近更新 更多