1

i know there are lot of solution regarding unrecognized token but all of them ocuuring while executing insert() query but i got error while creating a table. Here is a piece of code

def table_stats():
    c.execute("""CREATE TABLE stats(
            player text,
            matches real,
            runs real,
            100s real,
            50s real,
            value real,
            ctg text
        )""")
    conn.commit() 
table_stats()

sqlite3.OperationalError: unrecognized token: "100s" i am working on a simple project and in hint section of problem statement it shows '100s' attribute of table but in my code it produce a error.

kashif
  • 21
  • 6

1 Answers1

2

Identifiers (such as column names) can't start with digits. You could pick a different name (such as hundreds or num_100s) instead. E.g.:

CREATE TABLE stats(
    player text,
    matches real,
    runs real,
    num_100s real,
    num_50s real,
    value real,
    ctg text
)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Hmm. I received this "Unrecognized token" error for an existing table called "0D". Now trying to add any column to it fails. But surely if the table already exists as such there's a way to modify it? – jbplasma Apr 22 '22 at 14:48
  • @jbplasma execute the SQL w/ 0D passed as a string, like "ALTER TABLE '0D' ...". Works fine. – jbplasma Jan 05 '23 at 20:36