[DB-SIG] How to escape special field name, mysql?

Carsten Haese carsten at uniqsys.com
Wed Aug 8 03:58:22 CEST 2007


On Tue, 2007-08-07 at 21:37 -0400, Carsten Haese wrote:
> [...] The standard way (at least as far as
> Informix understands it) is not to quote table/column names at all and
> let the parser worry about determining whether the word it's looking at
> is the name of a thing or a keyword. And worry it will, if you are
> insane enough to write queries like "select select as as from from where
> where = 1", which is valid SQL given the right schema, and it's the
> reason why writing a standards compliant SQL parser is a pain in the
> neck.

Here's proof that this insane query really works, as long as you take my
word for it that this transcript isn't doctored:

Python 2.5 (r25:51908, Oct 28 2006, 12:26:14) 
[GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import informixdb
>>> conn = informixdb.connect("ifxtest")
>>> cur = conn.cursor()
>>> cur.execute("create temp table from (select int, where int)")
-1
>>> cur.execute("insert into from values(1,1)")
1
>>> cur.execute("insert into from values(2,2)")
1
>>> cur.execute("select select as as from from where where = 1")
>>> cur.fetchall()
[(1,)]

-- 
Carsten Haese
http://informixdb.sourceforge.net




More information about the DB-SIG mailing list