Cassandra CLI 命令与 cqlsh -e 如何声明

Cassandra CLI command with cqlsh -e how to declare

在我的 Cassandra table 中,它是用大写的所有列创建的。当我们尝试 select cqlsh 终端中的列时,我们能够 select 这些列,但是当我们尝试基于 cqlsh -e 提取相同的查询时,会遇到一些转义字符问题。

cqlsh:key1> select "PLAN_ID" ,"A_ADVERTISER_ID" ,"ADVERTISER_NAME"  from key1.plan_advertiser where "PLAN_ID" = '382633' and "A_ADVERTISER_ID" = 15019;

 PLAN_ID | A_ADVERTISER_ID | ADVERTISER_NAME
---------+-----------------+----------------------
  382633 |           15019 | Hanesbrands, Updated

NMH206576286LM:sparklatest0802 KarthikeyanDurairaj$ cqlsh -e 'select "PLAN_ID" ,
  "A_ADVERTISER_ID" ,"ADVERTISER_NAME"  from key1.plan_advertiser 
  where "PLAN_ID" = '382633' and "A_ADVERTISER_ID" = 15019'
<stdin>:1:InvalidRequest: Error from server: code=2200 [Invalid query] 
  message="Invalid INTEGER constant (382633) for "PLAN_ID" of type text"

NMH206576286LM:sparklatest0802 KarthikeyanDurairaj$ 

cqlsh 在这方面可能有点棘手。虽然它不允许您转义单引号,但它允许您转义双引号。这对我有用:

$ bin/cqlsh -u cassdba -p flynnLives -e "SELECT * FROM Whosebug.plan_advertiser
   where \"PLAN_ID\" = '382633' and \"A_ADVERTISER_ID\" = 15019"

 PLAN_ID | A_ADVERTISER_ID | ADVERTISER_NAME
---------+-----------------+----------------------
  382633 |           15019 | Hanesbrands, Updated

(1 rows)

这样,我们将CQL语句从单引号换成双引号,对列值使用单引号,然后转义掉列名两边的双引号。