CQL并非在字符串格式化期间转换所有参数

时间:2016-06-15 10:27:14

标签: python python-3.x cassandra cql

我尝试使用CQL中的Python执行插入语句。

表定义是:

CREATE TABLE test_keyspace.test_table (
key1 text PRIMARY KEY,
key2 text,
key3 int,
key4 float,
key5 float
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
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 = '99PERCENTILE';

Python代码是:

no_of_rows = 10000

insert_test_pre_stm = "INSERT INTO test_table (key1, key2, key3, key4, key5) VALUES (?, ?, ?, ?, ?)"


for row in range(no_of_rows):
    key = 'test' + str(row)
    session.execute(insert_test_pre_stm, [key, 'test', 1900, 1.0, 1.0])

错误是:

TypeError: not all arguments converted during string formatting

更新

我已经解决了问题,这是由于没有使用预准备语句(session.prepare)。

0 个答案:

没有答案