There are two tables

enter image description here

cdr is a local table on the FEDERATED engine, that is, it receives data from a remote server from a similar table in structure. It stores a lot of information about calls to the PBX, but you need to pull out certain numbers and put them in a separate table.

In MySQL Workbench, in the table editing section, I add a trigger.

CREATE DEFINER=`root`@`localhost` TRIGGER dials_insert AFTER INSERT ON calllist.cdr FOR EACH ROW BEGIN INSERT INTO calllist.dials (dials.CID, dials.calldate) SELECT src, calldate FROM calllist.cdr WHERE calldate = (SELECT MAX(calldate) FROM calllist.cdr); END 

After making a call, a record appears in the cdr, the record is not added to dials, however, if the script body is executed in the Workbench environment as a script, the dials record will be recorded, the code will be working.

Server 5.7.11

  • Strange why he gives create a trigger. It seemed to me that the federated is being addressed only when the request is working. Those. remote database where physically the table is not reporting itself about changes to the local one - Mike
  • It does not say - it is true, however, it seemed to me the local table of the change itself should notice and call a trigger. not? - BlackOverlord
  • I don’t know for sure, I haven’t come across such features and mysql, but the logic tells me that the remote server will not report. This is not replication, a remote server without a local request most likely will not do anything - Mike
  • By the way, as an option, in most cases the trigger on the eath row cannot read the table on which the trigger itself. - Mike
  • Now this is interesting, thank you, I will analyze this question in more detail - BlackOverlord

0