Valid SQL?

Tim Chase python.list at tim.thechases.com
Tue May 23 07:53:49 EDT 2006


> I have this string that I am sending via a Cursor.execute() using
> MySQLdb:
> 
> insert into table Ping82_eb13__elearn__ihost__com (`dateTime`,
> `values`) values(
> "Fri May 12 11:39:02 2006", "1")
> 
> Does anyone see anything wrong with this SQL syntax?

While this is the *python* list, rather than a SQL list...

It looks like you're using two diff. styles of quoting.  And 
using back-quotes at that.  IIRC, ANSI-SQL (nebulous standard as 
it is, implemented to taste by each vendor) calls for using 
single-quotes as strings.  Some RDBMS engines support the 
double-quote (MySQL does).  None that I know of support the 
back-tick.  Unless it's an RDBMS scheme for surrounding column or 
table-names that might have spaces in them (or might be SQL 
keywords).  You might also want to make sure that your RDBMS 
doesn't have a column data-type of "datetime" (MySQL does) which 
might choke matters too...having a column-name that potentially 
clashes with the name of a datatype is just asking for trouble :)

Additionally, the syntax for INSERT INTO statements usually 
leaves the word TABLE as optional.  I think this is the first 
time I've seen someone opt for it :)  Most SQL I've seen just does

INSERT INTO tblFoo (field1, field2) VALUES ('value1', 'value2')

You don't include the DDL that defines the structure of the table 
into which you're shoving matters, so it's somewhat hard to tell 
what's going on.  Are primary keys being violated?  Are 
data-types awry?

Lastly, you don't include the text of the error message that 
you're getting back...most error messages try to be helpful, and 
in this case, it would certainly be helpful. :)

Just a few thoughts,

-tkc







More information about the Python-list mailing list