backtick or quote?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

backtick or quote?

Post 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?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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 :)
Post Reply