How to insert map type into cassandra using cassandra-driver for python

青春壹個敷衍的年華 提交于 2021-02-20 14:58:05

问题


Since, cassandra supports map type. I want to insert a python dict into cassandra. I tried this:

cql = "Insert into table_name (my_key, name, my_dict) values (%s, %s, %s)" % (my_key, name, my_dict)

session.execute(cql)

This obviously didn't work.

I already have a map type column in my column family. How do I go about it?

Error: TypeError: not all arguments converted during string formatting


回答1:


Use parameter passing form instead of string interpolation:

cql = "Insert into table_name (my_key, name, my_dict) values (%s, %s, %s)"
session.execute(cql,  (my_key, name, my_dict))


来源:https://stackoverflow.com/questions/26191437/how-to-insert-map-type-into-cassandra-using-cassandra-driver-for-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!