You can use the back quote(`) to escape the field name. It's the ~ key on the keyboard.
tickets(`from`,`department`,...

If you type SHOW CREATE TABLE tickets, you'll see mysql escapes all the field names to avoid reserve word conflicts.

On Nov 29, 2005, at 2:14 PM, Rhino wrote:


----- Original Message ----- From: "Jeff" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Tuesday, November 29, 2005 11:42 AM
Subject: Insert query problem



All,

I can't get this query to run, it keeps compaining that there is a
problem:

The Query:

insert into
tickets (id,from,department,subject,body,lastaction,lastpost,priority,sta
tus,created,fromname,lastpostname,attach,ct,uniq,notify,replyto)
values(null,'jmckeon','1','test','test
test',unix_timestamp(now()),'"[EMAIL PROTECTED]"
<[EMAIL PROTECTED]>','Medium','Open',unix_timestamp(now()),'Jeff
McKeon','Jeff McKeon','','','ks5hslajdfasd','1','[EMAIL PROTECTED]')

The error:

You have an error in your SQL syntax near
'from,department,subject,body,lastaction,lastpost,priority,status,cre ate
d,fromnam' at line 1

I suspect it doesn't like the fact that I have a field named "from" but I KNOW it's possible to write to this table and that field, I just can't figure out the correct syntax to get it to accept the fieldname "from".


One of my least favourite aspects of MySQL is the vague error messages, like the one you quote in your post. I keep hoping that they will make them much clearer but it doesn't seem to have happened yet....

In any case, you may well be right that MySQL doesn't like you having a column named 'from'. Most dialects of SQL tolerate that kind of thing but usually require escape characters of some kind around words like 'from', which are keywords, when they are used outside of their normal purpose. I've never had the desire to call a column 'from' so I've never learned the escape character technique for MySQL so I would suggest the following possibilities:

- change your column name so that _isn't_ a keyword. That would be my first choice if it was my database. - search the MySQL manual for 'escape character' and/or 'keyword'; with a bit of luck, it is documented there somewhere - search the MySQL mailing list archives. I'm virtually positive I've seen the matter come up in the list but I just don't remember the escape syntax at the moment.

If you escape the column named 'from' and the query still doesn't work, please repost so that we can investigate other possibilities.

Rhino


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.10/186 - Release Date: 29/11/2005


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql? [EMAIL PROTECTED]




--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to