No viable alternative when typing 'mytable1' cassanda cql python session.execute error

I am trying to execute a simple cql query in python and I keep getting the error.

table1 = "mytable1"
table2 = "mytable2"

query1 = "SELECT * FROM %s"
table1Rows = session.execute(query1, (table1,))
table2Rows = session.execute(query1, (table2,))

      

The table variables are actually passed as arguments, but I just made my own example. I am getting this error:

cassandra.protocol.SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:14 no viable alternative at input 'mytable1' (SELECT * FROM ['mytable]...)">

      

I can't figure out what's wrong with my syntax. Please help. Thank!

+3


source to share


1 answer


Parameterized queries do not support providing the table name as a parameter. You can achieve this by constructing a query string using string concatenation. Just make sure the input variable is whitelisted to protect against SQL injection.



+3


source







All Articles