You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Andy Ballingall TF <ba...@thefoundry.co.uk> on 2012/08/15 11:06:45 UTC

CQL3: Do boolean values need quoting in inserts?

Hi,

I was following the examples on this page:

http://www.datastax.com/dev/blog/whats-new-in-cql-3-0#comment-116250

In the example, a table was created as follows:

CREATE TABLE altercations (
       instigator text,
       started_at timestamp,
       ships_destroyed int,
       energy_used float,
       alliance_involvement boolean,
       PRIMARY KEY (instigator, started_at)
   );

The example then showed an insert into this table:

INSERT INTO altercations (instigator, started_at, ships_destroyed,
energy_used, alliance_involvement)
VALUES ('Jayne Cobb', '7943-07-23', 2, 4.6, false);

This threw the following error:

Bad Request: line 3:65 no viable alternative at input ‘false’

I managed to get it to work by single-quoting the boolean value. And
if I look at the data, it does indeed seem to have worked:

cqlsh:test> select * from altercations;
instigator | started_at | alliance_involvement | energy_used | ships_destroyed
————+————————–+———————-+————-+—————–
Jayne Cobb | 7943-07-23 00:00:00+0000 | False | 4.6 | 2


I was using cqlsh -3 ( cqlsh 2.2.0 | Cassandra 1.1.2 | CQL spec 3.0.0
| Thrift protocol 19.32.0)

Is this a bug, or must we quote booleans in CQL?

Thanks
Andy

-- 
Andy Ballingall
Senior Software Engineer

The Foundry
6th Floor, The Communications Building,
48, Leicester Square,
London, WC2H 7LT, UK
Tel: +44 (0)20 7968 6828 - Fax: +44 (0)20 7930 8906
Web: http://www.thefoundry.co.uk/

The Foundry Visionmongers Ltd.
Registered in England and Wales No: 4642027

Re: CQL3: Do boolean values need quoting in inserts?

Posted by aaron morton <aa...@thelastpickle.com>.
Quoting false is correct from my reading of the Antlr grammar. 

Constant terms are either strings, UUID, int or long. 

I'm sure someone from DS will pickup the comment you made on the post and fix the example. 

Cheers
 
-----------------
Aaron Morton
Freelance Developer
@aaronmorton
http://www.thelastpickle.com

On 15/08/2012, at 9:06 PM, Andy Ballingall TF <ba...@thefoundry.co.uk> wrote:

> Hi,
> 
> I was following the examples on this page:
> 
> http://www.datastax.com/dev/blog/whats-new-in-cql-3-0#comment-116250
> 
> In the example, a table was created as follows:
> 
> CREATE TABLE altercations (
>       instigator text,
>       started_at timestamp,
>       ships_destroyed int,
>       energy_used float,
>       alliance_involvement boolean,
>       PRIMARY KEY (instigator, started_at)
>   );
> 
> The example then showed an insert into this table:
> 
> INSERT INTO altercations (instigator, started_at, ships_destroyed,
> energy_used, alliance_involvement)
> VALUES ('Jayne Cobb', '7943-07-23', 2, 4.6, false);
> 
> This threw the following error:
> 
> Bad Request: line 3:65 no viable alternative at input ‘false’
> 
> I managed to get it to work by single-quoting the boolean value. And
> if I look at the data, it does indeed seem to have worked:
> 
> cqlsh:test> select * from altercations;
> instigator | started_at | alliance_involvement | energy_used | ships_destroyed
> ————+————————–+———————-+————-+—————–
> Jayne Cobb | 7943-07-23 00:00:00+0000 | False | 4.6 | 2
> 
> 
> I was using cqlsh -3 ( cqlsh 2.2.0 | Cassandra 1.1.2 | CQL spec 3.0.0
> | Thrift protocol 19.32.0)
> 
> Is this a bug, or must we quote booleans in CQL?
> 
> Thanks
> Andy
> 
> -- 
> Andy Ballingall
> Senior Software Engineer
> 
> The Foundry
> 6th Floor, The Communications Building,
> 48, Leicester Square,
> London, WC2H 7LT, UK
> Tel: +44 (0)20 7968 6828 - Fax: +44 (0)20 7930 8906
> Web: http://www.thefoundry.co.uk/
> 
> The Foundry Visionmongers Ltd.
> Registered in England and Wales No: 4642027