Page 1 of 1
backtick or quote?
Posted: Thu Dec 20, 2007 6:54 am
by alex.barylski
When using PMA I often see that the program automatically wraps tables and variable names inside backticks. What is the meaning of this?
I have never used a backtick (I only wrap varchar, etc inside single or double quotes) and yet my MySQL runs fine???
What is this operator for in the context of MySQL? Is it escaping the table names, fields, etc?
Posted: Thu Dec 20, 2007 8:41 am
by Kieran Huggins
That's exactly what it is.
Database, table, index, column, and alias names are "identifiers" in SQL, which are escaped with backticks. It's similar to the :symbol in Ruby - it takes the guesswork out of the parser that the string might be just a string.
I got into the habit of always quoting everything, just to be safe. I think it cost me a few debugging hours once... now I'm twice shy.
Posted: Thu Dec 20, 2007 8:56 am
by feyd
It's not really about making it easier for the parser… It's intention is to remove errors due to bad naming choices. People tend to use field and table names which are keywords; few of which MySQL will accept as not a keyword in the contextual use. Provided you do not use keywords as table and field names, you're fine and don't need to use them.
Posted: Thu Dec 20, 2007 1:53 pm
by alex.barylski
feyd wrote:It's not really about making it easier for the parser… It's intention is to remove errors due to bad naming choices. People tend to use field and table names which are keywords; few of which MySQL will accept as not a keyword in the contextual use. Provided you do not use keywords as table and field names, you're fine and don't need to use them.
Ah yes....now I recall having read that sometime ago.
Thanks
