I'm looking for a function that insert data if they are not existing.
I tried with IF not exists but I think that my mariadb version is no up enought to handle this.
So I'm trying with NOT IN, but get the same issue...
CREATE DEFINER=`root`@`localhost` PROCEDURE `close_ticket`(IN idT INT,IN accuse VARCHAR(45),IN lienAccuse VARCHAR(60), IN lienG VARCHAR(60),IN jours INT,IN reason VARCHAR(250), IN isclosed BOOLEAN)
BEGIN
INSERT INTO bot_onet.accuse (`Pseudo`,`lienFaceit`) SELECT accuse,lienAccuse
WHERE lienAccuse NOT IN(SELECT `lienFaceit` FROM `bot_onet`.`accuse` );
SELECT @ID := `idAccuse` FROM bot_onet.accuse WHERE `lienFaceit` = lienAccuse;
INSERT INTO bot_onet.ticket_has_accuse (`Ticket_idTicket`,`Accuse_idAccuse`,`duree`,`timecode`,`unbaned`,`raison`) VALUES (idT,@ID,jours,unix_timestamp(),FALSE,reason) ;
UPDATE bot_onet.ticket SET `Fermeture` = unix_timestamp(),`closed` = isclosed, `LienGame` = LienG WHERE idTicket = idT;
END
Piece of code which create the bug
INSERT INTO `bot_onet`.`Accuse` (`Pseudo`,`lienFaceit`) SELECT 'C0casio45','test'
WHERE 'C0casio45' NOT IN(SELECT `Pseudo` FROM `bot_onet`.`Accuse`)
error code
09:52:12
INSERT INTO bot_onet.Accuse (`Pseudo`,`lienFaceit`) SELECT 'test','faceit/test'
WHERE lienAccuse NOT IN(SELECT lienAccuse FROM bot_onet.Accuse ) Error Code: 1064.
You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax to use near
'WHERE lienAccuse NOT IN(SELECT lienAccuse FROM bot_onet.Accuse )' at line 2
0.110 sec
And if i use the from statement, it returns no error but he is not insert data too
INSERT INTO `bot_onet`.`Accuse` (`Pseudo`,`lienFaceit`) SELECT 'C0casio45','test'
FROM `bot_onet`.`Accuse` WHERE 'C0casio45' NOT IN(SELECT `Pseudo` FROM `bot_onet`.`Accuse`)