I am using Mariadb (10.5.12-MariaDB-1build1) on Ubuntu.
I had created an insert trigger on a table; that uses union statement to check for previous records. It work fine in previous version (10.3.31-MariaDB-0ubuntu.20.04.1) but throw error in this version
I had simplified the statement
SET @ID = '';
union is on several table but I had reduced it to two
SELECT id FROM table1
union
SELECT id
INTO @ID
FROM table2;
Give me this error
ERROR 1064 (42000): 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 'FROM table2 at line 'line number'
Obviously if i comment the INTO clause it is fine.
So i guess problem is in INTO. i guess more specifically the placement of into. Because single select statement doesn't give any error.
I will check into documentation for what i am doing wrong.
@Barmar here is the actual code
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER CRPInsertTrigger
BEFORE INSERT ON CRP
FOR EACH ROW
BEGIN
SET @msg = '';
SET @tire = @ID = @Name = '';
SELECT 'coMem' `tire`, coMemID `ID`, coMemName `Name` FROM coMem
WHERE institute = NEW.institute and registration = NEW.registration and bookNo = NEW.bookNo
union
SELECT 'commercialMem' `tire`, commercialMemID `ID`, commercialMemName `Name` FROM commercialMem
WHERE institute = NEW.institute and registration = NEW.registration and bookNo = NEW.bookNo
union
SELECT 'communityGeneralMem' `tire`, communityGeneralMemID `ID`, communityGeneralMemName `Name` FROM communityGeneralMem
WHERE institute = NEW.institute and registration = NEW.registration and bookNo = NEW.bookNo
union
SELECT 'CRP' `tire`, CRPID `ID`, CRPName `Name` FROM CRP
WHERE institute = NEW.institute and registration = NEW.registration and bookNo = NEW.bookNo
union
SELECT 'lsoMem' `tire`, lsoMemID `ID`, lsoMemName `Name` FROM lsoMem
WHERE institute = NEW.institute and registration = NEW.registration and bookNo = NEW.bookNo
union
SELECT 'voMem' `tire`, voMemID `ID`, voMemName `Name`
INTO @tire, @ID, @Name FROM voMem
WHERE institute = NEW.institute and registration = NEW.registration and bookNo = NEW.bookNo;
IF @Name != '' THEN
SET @msg = CONCAT('Error: Duplicate in registration found: ', CAST(NEW.registration AS CHAR CHARACTER SET utf8) COLLATE utf8_bin);
SET @msg = CONCAT(@msg, '(', @tire, 'ID:',CAST(@ID AS CHAR CHARACTER SET utf8) COLLATE utf8_bin);
SET @msg = CONCAT(@msg, ', Name:', CAST(@Name AS CHAR CHARACTER SET utf8) COLLATE utf8_bin, ')');
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @msg;
END IF;
END */;;
DELIMITER ;