1

I have a little issue with my python code. I want to take the input from user and based on that create an SQL table with that name. I take the input in table_name variable and want to do it so:

sql = "CREATE TABLE %s" % table_name
cur.execute(sql)

Let's say I run it with input "books". I get this error:

File "XXX", line 55, in FUNCTIONNAME
cur.execute(sql)
sqlite3.OperationalError: near "books": syntax error

Any ideas on what is wrong? I googled it and above code should be OK, but it isn't...

1 Answer 1

4

That's most probably cause you are not passing the table definition (column names and their type , size). What I see from posted code is that you are passing only table name and so your query becomes below which is totally wrong

CREATE TABLE books
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, you are right. I wanted to make it without any columns (on purpose), but didn't realise that is nercessary. thank's for help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.