Comments - Help changing update command to trigger (answered)

3 years, 9 months ago Shawn Logan

I appreciate this community, thank you for this help. I am trying to watch table: telemetry_log for any insert. Upon any insert on telemetry_log i would like to update the column: device_desc of that newly inserted row with the device_desc from table: id_name_update based on matching device_ids. Currently the command is running our of a bash script that uses the data remotely.

I understand the basic principles of triggers, as I said i tried 100's of different possibilities.

HERE ARE SOME FAILED ATTEMPTS

DROP IF EXISTS TRIGGER add_desc

DELIMITER $$

CREATE TRIGGER add_desc BEFORE INSERT ON telemetry_log FOR EACH ROW BEGIN INSERT device_desc INTO NEW.device_desc FROM id_name_update; END$$

DELIMITER ;

DROP IF EXISTS TRIGGER add_desc DELIMITER CREATE TRIGGER add_desc BEFORE INSERT ON telemetry_log BEGIN

INSERT device_desc INTO NEW.device_desc From id_name_update WHERE NEW.device_id = device_id; END DELIMITER ; __

CREATE TRIGGER add_desc AFTER INSERT ON telemetry_log BEGIN UPDATE telemetry_log SET id_name_update ON telemetry_log.device_id = id_name_update.device_id SET telemetry_log.device_desc = id_name_update.device_desc WHERE telemetry_log.device_desc IS NULL"; END;

DROP IF EXISTS TRIGGER add_desc

DELIMITER $$

CREATE TRIGGER add_desc before insert on telemetry_log

UPDATE telemetry_log SET NEW.device_desc = id_name_update.device_desc WHERE NEW.devie_desc IS NULL;

end; $$ delimiter ;

DROP IF EXISTS TRIGGER add_desc

DELIMITER $$

CREATE TRIGGER add_desc before insert on telemetry_log

UPDATE telemetry_log JOIN id_name_update ON telemetry_log.device_id = id_name_update.device_id SET telemetry_log.device_desc = id_name_update.device_desc WHERE telemetry_log.devie_desc IS NULL;

end; $$ delimiter ;

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.