Dave Guy
Dave Guy

Reputation: 9

Error 1064 when creating Trigger

I am using MYSQL 5.6 and phpMyAdmin 4.1.14

I am trying to create a Trigger that will copy data from one db to another but get the following error:

#1064 - 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 'new.airplane_id,new.user_id,new.icao24,new.created_at,new.timestamp,new.altitude' at line 7

Any pointers would be gratefully received

My code is:

CREATE TRIGGER airfields_insert 
BEFORE INSERT 
ON realtime 
FOR EACH ROW
BEGIN
if (new.squawk between 6160 and 6167 or new.squawk between 6171 and 6177) and new.altitude <= 4000 then 
insert into airfields (airplane_id,user_id,icao24,created_at,timestamp,altitude,flight_number,latitude,longitude,heading,squawk,horizontal_speed,vertical_speed,Interested) (new.airplane_id,new.user_id,new.icao24,new.created_at,new.timestamp,new.altitude,new.flight_number,new.latitude,new.longitude,new.heading,new.squawk,new.horizontal_speed,new.vertical_speed,new.Interested);
end if;

Upvotes: 0

Views: 123

Answers (2)

Ajmal Muhammad
Ajmal Muhammad

Reputation: 695

You have Syntax error in insert query Your QUERY should be like that

insert into airfields (airplane_id,user_id,icao24,.......) 
values (new.airplane_id,new.user_id,new.icao24,........);

or simply

 insert into airfields values (new.airplane_id,new.user_id,new.icao24,........);

The form does not specify the column names where the data will be inserted, only their values:

Upvotes: 2

Rahul
Rahul

Reputation: 77876

You are missing the VALUES keyword in your INSERT statement

Your current INSERT query

insert into airfields (airplane_id,user_id,icao24,.......) 
(new.airplane_id,new.user_id,new.icao24,........);
end if;

It should be

insert into airfields (airplane_id,user_id,icao24,.......) 
values (new.airplane_id,new.user_id,new.icao24,........);
end if;

Also, you are missing the END keyword after END IF

Upvotes: 0

Related Questions