2

when I want to update a set item in Cassandra table with python code like following

ps = session.prepare( """ UPDATE test,tbl SET val = val + {'?'} where name = ? and id = ?;""" )
bs = bind(ps, ['name', 'name', 1])
session.execute(bs)

I got error

Too many arguments provided to bind() (got 3, expected 2)

the problem is {'?'} that cant identified by prepared. I test {\'?\'} but nothing change.

ghanad
  • 68
  • 6

1 Answers1

1

Update: forgot about that syntax...

You need to use following syntax:

UPDATE test,tbl SET val = val + ? where name = ? and id = ?;

and bind with set as first parameter:

bs = bind(ps, [set(['name']), 'name', 1])

Original answer:

You don't need to put quotes around ? character - when bind happens, it's correctly quotes the text & other types.

P.S. Please note, that if you use {?}, this means that you always insert one element into the set. If you need more, then you need to use just ?, and pass a python set as an argument.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • when I remove quotes form ? I got following error Invalid set literal for val: bind variables are not supported inside collection literals – ghanad Jun 09 '20 at 13:08