Reply to topic
sql syntax to insert values with reserved words
dbsturtevant


Joined: 08 Apr 2008
Posts: 3
Reply with quote
Hi, I suspect there is a very easy answer for this, but I'm not sure what it is...
I recently switched to a new hosting service and suddenly the sql routines that used to run fine are having trouble. Specifically, I'm getting a syntax error 1064. I suspect this is related to reserved words ('and' and 'on') in the values for the data that I am trying to insert. I tried using ' ' ' and ' " ' around the values but that didn't work. Any other ideas?
Thanks,
Dave
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1047
Location: Felton, Delaware
Reply with quote
If you can provide me a more specific example of a query/command gone awry, I can help you fix it Wink

But taking a preliminary stab at this one... you can try delimiting those words with double quotes, but usually that only applies when they're being used as identifiers. Those words appearing in the data should not cause any problems and is why I asked to see a more specific and complete query/command as I suspect it's something else causing the issue.
dbsturtevant


Joined: 08 Apr 2008
Posts: 3
Reply with quote
I appreciate your help.
Here's a sample query:

INSERT INTO table (title, table.year, table.medium, table.keyword)
VALUES (‘Jackson, MA’, ‘2008’, ‘acrylic and oil on board’, ‘Jackson, MA, colonial, northeast’);

Where the single quotes are now, I tried using full quotes, but that didn't seem to help. In both cases I get the following error message:

SQL query:
INSERT INTO table( title, table.year, table.medium, table.keyword )
VALUES (
‘Jackson, MA’, ‘2008’, ‘acrylic
AND oil ON board’, ‘Jackson, MA, colonial, northeast’
)
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'on board’, ‘Jackson, MA, colonial, northeast’)' at line 2
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1047
Location: Felton, Delaware
Reply with quote
The only thing I've done is change your single quotes to these: '

by hitting the double quote " key next to the enter button. After doing that it all seemed to work fine for me. Those funky single quotes seem to be the issue as I recreated the error exactly, and then I fixed it. Just change the quotes to standard single quotes Wink
dbsturtevant


Joined: 08 Apr 2008
Posts: 3
Reply with quote
Ahhh! I knew it had to be something simple!
Thank you for your help!!!
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1047
Location: Felton, Delaware
Reply with quote
Anytime Smile Glad I could be of service.
sql syntax to insert values with reserved words
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic