user2540748
user2540748

Reputation:

SQLite Insert into where error

I'm trying to use the following code

cursor.execute("INSERT INTO players (wins) VALUES (?) WHERE username = ?", (wins[3], players))

and am getting the following error

    cursor.execute("INSERT INTO players (wins) VALUES (?) WHERE username = ?", (wins[3], players))
sqlite3.OperationalError: near "WHERE": syntax error

My table has two columns, username and wins. Wins[3] is the list value that stores the win integer, and players is the username.

Upvotes: 0

Views: 551

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1125078

There is no WHERE part in an INSERT statement; INSERT only adds a new row, so there is nothing to limit what existing rows the statement applies to here.

You want to use an UPDATE instead:

cursor.execute("UPDATE players SET wins=? WHERE username = ?", (wins[3], players))

Upvotes: 2

Related Questions