0

I am not able to find out what is the exact issue. When I remove index param from below mentioned query and try to insert the data it works fine, but trying to add index cause an error. Here is my table schema:

CREATE TABLE IF NOT EXISTS `address_list` (
  `email` varchar(100) NOT NULL,
  `currency_name` varchar(50) NOT NULL,
  `address` varchar(50) NOT NULL,
  `label` varchar(100) NOT NULL,
  `index` int DEFAULT 0,
  `address_type` varchar(50) NOT NULL,
  `balance` varchar(500) DEFAULT "0.0",
  `timestamp` TIMESTAMP default CURRENT_TIMESTAMP
)

and here is my insert query :

insert into address_list (email,currency_name,address,label,index,address_type) Values ('[email protected]','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');

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 'index) Values ('[email protected]','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X'' at line 1
2
  • 2
    index is a reserved word, it needs to be quoted. Voting to close this question as a typo. Commented Nov 5, 2020 at 18:43
  • @GMB how is that a typo? surely it would be better to find an appropriate question to mark this a duplicate of Commented Nov 5, 2020 at 18:44

1 Answer 1

2

index is a reserved word in mysql; rename your column to something else, or else place it in backticks where you want to use it:

insert into address_list (email,currency_name,address,label,`index`,address_type) Values ('[email protected]','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');

See https://dev.mysql.com/doc/refman/8.0/en/keywords.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.