I have created the following table:
CREATE TABLE `test2` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`A` varchar(30) DEFAULT NULL,
`B` varchar(30) DEFAULT NULL,
`C` varchar(30) DEFAULT NULL,
`D` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8
When I insert a row like this
insert into test2 (A, B, C, D) values ('a', 'b', 'c', 'd')
The insertion is successfull, but if I try to insert a row with a different value at column A, e.g.
insert into test2 (A, B, C, D) values ('aaa', 'b', 'c', 'd')
then I get error 1136: Column count doesn't match value count at row 1. Can someone please help me understand the problem? I have read similar questions but I can not find what is wrong in this case.
The table has the following trigger:
DELIMITER $$
CREATE TRIGGER test_update
AFTER INSERT
ON test2 FOR EACH ROW
BEGIN
IF NEW.A IN (select A from test1) THEN
update test1
set test1.B = new.B,
test1.C = new.C,
test1.D = new.D
where test1.A = new.A;
ELSEIF NEW.A NOT IN (select A from test1) THEN
INSERT INTO test1 values (new.A, new.B, new.C, new.D);
END IF;
END$$
DELIMITER ;
The purpose of the trigger is to update the table "test1" if the value of column A already exists in a row of "test1", or to insert a new row in "test1" if the value of A doesn't exist.
CREATE TABLE `test1` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`A` varchar(30) DEFAULT NULL,
`B` varchar(30) DEFAULT NULL,
`C` varchar(30) DEFAULT NULL,
`D` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8