Search code examples
mysqlsqlmysql-error-1064

MySQL Syntax Error "right syntax to use near 'desc"


I'm working in Python and using the MySQLdb module. I have a working connection (I can run other queries successfully)

c.execute("ALTER TABLE results ADD COLUMN desc TEXT")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35,
    in defaulterrorhandler
    raise errorclass, errorvalue

I'm getting the following error:

_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near 'desc TEXT' at line 1")

I've had similar trouble before; MySQLdb's syntax error messages are terribly non-descriptive.

How can this be fixed?


Solution

  • I believe desc is reserved. It is used in an ORDER BY clause

    You may be able to get away with using it if you put back-ticks around it, but I think you would be better off changing the name to a non-reserved word.