0

I currently have a MySQL table that looks like:

mysql> SELECT * FROM settings;
+--------------+-------+
| name | value |
+--------------+-------+
| connected | 0 |
+--------------+-------+

and I'm trying to update the value with a timestamp for connected through Python with this code:

db1 = MySQLdb.connect(host="localhost", user="user", passwd="password", db="database")
cursor1 = db1.cursor()
cursor1.execute("UPDATE settings SET value = 'ts' WHERE name = connected")
db1.commit()
cursor1.close()

This returns to me:

cursor1.execute("""UPDATE settings SET value = 'ts' WHERE name = connected""")
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue _mysql_exceptions.OperationalError: (1054, "Unknown column 'connected' in 'where clause'")

and I just can't figure it out. Any help would be really appreciated.

Arulkumar
13.3k15 gold badges51 silver badges76 bronze badges
asked Jul 19, 2016 at 12:50
1
  • 6
    Your query is trying to compare the name column to a column called connected. If you want to compare the name column to the literal string "connected", then you mean WHERE name='connected' Commented Jul 19, 2016 at 12:51

1 Answer 1

1

1054, "Unknown column 'connected' in 'where clause'

This error clearly states that connected is consider as a column name.

But here connected is string value that want to match with the columnname name.

So you need to place a single quote around the connected string to solve the issue:

cursor1.execute("UPDATE settings SET value = 'ts' WHERE name = 'connected'")
answered Jul 19, 2016 at 12:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.