paxton91michael
paxton91michael

Reputation: 77

MYSQL INSERT INTO; Invalid Syntax

If duplicate, please mark as I cannot otherwise find a solution.

I am executing a very simple SQL command that I have executed many other times in other environments but cannot find a rhyme or reason to this syntax error.

INSERT INTO tracking (range,purchase,trade_id) VALUES ("119.43-119.57","119.50","pid","961971");

I have tried this as well:

INSERT INTO tracking (range,pid,purchase,trade_id) VALUES ('119.43-119.57','119.50','pid','961971');

As well as not quoting numbers (trade_id).

I am receiving error:

ERROR 1064 (42000): 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 'range,purchase,pid,trade_id) VALUES('119.43-119.57','119.50','pid' at line 1

My table structure:

+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| trade_id | varchar(125) | NO   | PRI | NULL    |       |
| pid      | varchar(125) | NO   |     | NULL    |       |
| purchase | varchar(125) | NO   |     | NULL    |       |
| range    | varchar(125) | NO   |     | NULL    |       |
| sell     | varchar(5)   | YES  |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

And then my SQL version:

+-------------------------+
| VERSION()               |
+-------------------------+
| 5.5.60-0ubuntu0.14.04.1 |
+-------------------------+
1 row in set (0.00 sec)

I am also running on an Ubuntu 14.04 and running these commands from SQL CLI (Command Line Interface).

If anybody has a pointer of something I am blatantly missing, please show the way. I am going batty.

Thank you in advance.

Upvotes: 0

Views: 1668

Answers (4)

Krishna Devashish
Krishna Devashish

Reputation: 86

Have you tried this out

INSERT INTO 'tracking' (range,pid,purchase,trade_id) VALUES ('119.43-119.57','119.50','pid','961971');

Upvotes: 1

Damian Dziaduch
Damian Dziaduch

Reputation: 2127

Fixed query by suggestion from deadman:

INSERT INTO `tracking` (`range`, `purchase`, `pid`, `trade_id`) VALUES ("119.43-119.57", "119.50", "pid", "961971");

Upvotes: -1

Saurabh Ande
Saurabh Ande

Reputation: 427

You can try this

INSERT INTO tracking (`range`,`pid`,`purchase`,`trade_id`) VALUES (`119.43-119.57`,`119.50`,`pid`,`961971`);

Upvotes: 1

munsifali
munsifali

Reputation: 1733

Documentation

Certain keywords, such as SELECT, DELETE, or BIGINT, are reserved and require special treatment for use as identifiers such as table and column names

The simplest solution is simply to avoid using reserved words as identifiers.

Upvotes: 1

Related Questions