0

This is currently all that I have simply because I wanted to test adding items to a table, and making sure that said item wasn't a duplicate. I saw that if you add INSERT IGNORE that it supposedly stops the creation of duplicated items but in my case, that didn't work.

CREATE TABLE IF NOT EXISTS testing (test0 TEXT, test10 TEXT);

INSERT IGNORE INTO testing VALUES ("TEST1","TEST2");
INSERT IGNORE INTO testing VALUES ("TEST1","TEST2");
INSERT IGNORE INTO testing VALUES ("TEST1","TEST2");
INSERT IGNORE INTO testing VALUES ("TEST1","TEST2");
INSERT IGNORE INTO testing VALUES ("TEST1","TEST2");
Gravity
  • 23
  • 7
  • It’ s A duplicate on indexes, which you don’t have – P.Salmon Feb 07 '22 at 14:45
  • Does this answer your question? ["INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"](https://stackoverflow.com/questions/548541/insert-ignore-vs-insert-on-duplicate-key-update) – D-Shih Feb 07 '22 at 14:48

2 Answers2

0

INSERT IGNORE just works in case of avoiding errors when you do the insert statement, it simply gonna let you insert the values because as I see there is not an identifier or PRIMARY KEY or UNIQUE CONSTRAINT to identify each element as unique that key is the one who cannot be duplicate, the "test01" and "test10" are just normal data types.

Ury17
  • 26
  • 4
0

The purpose of INSERT IGNORE, is to not interrupt the execution of insert statements if one fails for any reason. For example if you try to insert string value in a Integer column, it would just ignore the error and insert nothing then.

I think in your case you need to create a UNIQUE constraint for desired fields :)

  • 1
    After asking the question, I noticed that it doesn't even really apply to what I am trying to do, what I'm trying to do is in python and I can just check if the item already exists over there, and if it does then I will just skip it. When I asked the question I was thinking that I was stuck in MySQL for some reason. Thanks anyways! – Gravity Feb 07 '22 at 15:09