Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sqlite3 OperationalError: near ")": syntax error

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you in advance!

>Solution :

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('"','""')))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading