Sqlite3 OperationalError: near ")": syntax error
Question:
I am trying to create a table with a specific name based on a user’s ID (specifically, the user who started the interaction). I don’t know if its important or not but I am using asqlite which is a simple async wrapper for sqlite3.
Here is the code:
tableName=f'table_{userID}'
await cursor.execute("""CREATE TABLE IF NOT EXISTS "{}" (
item1 INTEGER PRIMARY KEY,
item2 TEXT,
item3 TEXT,
item4 TEXT,
item5 INTEGER,
item6 TEXT,
item7 INTEGER,
)""".format(tableName.replace('"','""')))
Received error:
sqlite3.OperationalError: near ")": syntax error
Thank you in advance!
Answers:
You have just mad a smal type error in your SQL syntax. Just remove the last ,
on the end and it should work.
tableName=f'table_{userID}'
await cursor.execute("""CREATE TABLE IF NOT EXISTS "{}" (
item1 INTEGER PRIMARY KEY,
item2 TEXT,
item3 TEXT,
item4 TEXT,
item5 INTEGER,
item6 TEXT,
item7 INTEGER
)""".format(tableName.replace('"','""')))
I am trying to create a table with a specific name based on a user’s ID (specifically, the user who started the interaction). I don’t know if its important or not but I am using asqlite which is a simple async wrapper for sqlite3.
Here is the code:
tableName=f'table_{userID}'
await cursor.execute("""CREATE TABLE IF NOT EXISTS "{}" (
item1 INTEGER PRIMARY KEY,
item2 TEXT,
item3 TEXT,
item4 TEXT,
item5 INTEGER,
item6 TEXT,
item7 INTEGER,
)""".format(tableName.replace('"','""')))
Received error:
sqlite3.OperationalError: near ")": syntax error
Thank you in advance!
You have just mad a smal type error in your SQL syntax. Just remove the last ,
on the end and it should work.
tableName=f'table_{userID}'
await cursor.execute("""CREATE TABLE IF NOT EXISTS "{}" (
item1 INTEGER PRIMARY KEY,
item2 TEXT,
item3 TEXT,
item4 TEXT,
item5 INTEGER,
item6 TEXT,
item7 INTEGER
)""".format(tableName.replace('"','""')))