ERROR 1064 (42000) - can't find the mistake in the SQL query

Viewed 1597

I've table named networks:

mysql> describe networks;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| range | varchar(45) | NO   |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

I'm trying to INSERT value in this table with the following query:

INSERT INTO networks(range) VALUES("10.10.10.10/24");

However I get this 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) VALUES("10.10.10.10/24")' at line 1

I tried playing with the quotes (changing them form " to ', and similar stuff), however it didn't work. Any ideas what may be wrong?

2 Answers

You can use the following INSERT:

INSERT INTO `networks` (`range`) VALUES ('10.10.10.10/24');

You can enclose table and column names into backticks to avoid conflicts with reserved words on MySQL. In your case RANGE is a reserved word and can't be used as a column or table name without backticks. A string value should be enclosed in single-quotes.

Note: You should avoid using reserved words like RANGE as column and table definition. You can find a list of all reserved words on the official docs.

Try Back Ticks:

INSERT INTO networks(`range`) VALUES('10.10.10.10/23');

This may help.

Related