我正在使用Cassandra,视觉信息是这样的:
[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]
我发现在CQL
中,可以插入布尔值。 cql insert
我的表架构是这样的:
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 :(得分:1)
> 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
值,或者在这种情况下为name
:
> insert into crew (name,alliance_trouble) values ('Malcolm Reynolds',true);
> SELECT * FROM crew;
name | alliance_trouble | bunk
------------------+------------------+------
Malcolm Reynolds | True | null
(1 rows)