Using the MySQLdb module

Carsten Gaebler news at snakefarm.org
Thu Apr 24 04:46:49 EDT 2003


In Michael Mayhew wrote:
> _mysql_exceptions.OperationalError: (1054, "Unknown column 'atr' in 
> 'field list'")
> 
> sql = "insert into refFlatHum values ( %s, %s, %d, %d )" % ('atr', 
> 'chr1', 90810, 92190)
> 
> c.execute(sql)

What you need here is documentation on SQL, not on MySQLdb. :-) If you want to
use strings in a query you need to enclose them in single or double quotes but
the query string in your example actually looks like this:

"insert into  refFlatHum values ( atr, chr1, 90810, 92190)"

The correct syntax would be:

"insert into  refFlatHum values ( 'atr', 'chr1', 90810, 92190)"

Note the single quotes around atr and chr1. To achieve this in your code you
will have to say:

sql = "insert into refFlatHum values ( %s, %s, %d, %d )" % \
("'atr'", "'chr1'", 90810, 92190)


cg.




More information about the Python-list mailing list