cassandra - Cassandra插入布尔错误

  显示原文与译文双语对照的内容
0 0

我用 Cassandra,视觉信息就像这样:


[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]

我在 CQL 中发现,布尔可以插入。 插入

我的表架构如下所示:


CREATE TABLE test.crew (
name text PRIMARY KEY,
alliance_trouble boolean,
bunk int
) WITH bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL","rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';

当我使用 CQL 插入


insert into crew (alliance_trouble) values ('true');

它显示:


 code=2200 [Invalid query] message="Invalid STRING constant (true) for"alliance_trouble" of type boolean" 

这里有什么问题如何在Cassandra中插入 boolean 类型?

时间: 原作者:

0 0

> insert into crew (alliance_trouble) values ('true');
code=2200 [Invalid query] message="Invalid STRING constant (true) for"alliance_trouble" of type boolean"

这里有两个问题。 #1, 你正在将值 true 作为字符串常量插入。 去掉单引号。 但即使是这样也不能完全解决这个问题:


> insert into crew (alliance_trouble) values (true);
code=2200 [Invalid query] message="Missing mandatory PRIMARY KEY part name"

如果不指定主键,则不能指定值,在这种情况下也不能使用:


> insert into crew (name,alliance_trouble) values ('Malcolm Reynolds',true);
> SELECT * FROM crew;
 name | alliance_trouble | bunk
------------------+------------------+------
 Malcolm Reynolds | True | null

(1 rows)

原作者:
...