代码之家  ›  专栏  ›  技术社区  ›  Karthikeyan Rasipalay Durairaj

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

  •  1
  • Karthikeyan Rasipalay Durairaj  · 技术社区  · 6 年前

    在我的Cassandra表中,它是用大写的所有列创建的。当我们试图在cqlsh终端中选择列时,我们能够选择那些列。但是当我们试图基于 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$ 
    

    当做 杜拉伊拉杰

    1 回复  |  直到 6 年前
        1
  •  1
  •   Aaron    6 年前

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

    $ bin/cqlsh -u cassdba -p flynnLives -e "SELECT * FROM stackoverflow.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语句从单引号切换到双引号,为列值使用单引号,然后转义出列名周围的双引号。