Rewrite trigger from PostgreSQL to MySQL I have this trigger in PostgreSQL database:

CREATE FUNCTION connections_insert_update_connection_root_fnc() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
            BEGIN
                UPDATE connections SET connection_root = connection WHERE connection = NEW.connection AND NEW.connection_root IS NULL;
                RETURN NEW;
            END;
            $$;


How it will look in MySQL please? 

The table connections in MySQL looks this:

| connections | CREATE TABLE `connections` (
  `connection` int(11) NOT NULL AUTO_INCREMENT,
  `connection_type` text,
  `connection_transport` text,
  `connection_protocol` text,
  `connection_timestamp` int(11) DEFAULT NULL,
  `connection_root` int(11) DEFAULT NULL,
  `connection_parent` int(11) DEFAULT NULL,
  `local_host` text,
  `local_port` int(11) DEFAULT NULL,
  `remote_host` text,
  `remote_hostname` text,
  `remote_port` int(11) DEFAULT NULL,
  PRIMARY KEY (`connection`),
  KEY `local_port` (`local_port`),
  KEY `connection_parent` (`connection_parent`),
  KEY `connection_root` (`connection_root`),
  KEY `connection_timestamp` (`connection_timestamp`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |


I tried this. It is semantic correct please?

CREATE TRIGGER connections_INSERT_update_connection_root_trg AFTER INSERT ON connections 
FOR EACH ROW 
BEGIN
    IF connection = NEW.connection AND NEW.connection_root IS NULL THEN
    UPDATE connections SET connection_root = connection WHERE connection = new.connection AND new.connection_root IS NULL;
    END IF;
END$$


Thank you for your help.
You cannot do this in an AFTER INSERT trigger. Why ???

According to the Book



Chapter 19 Page 251 Paragraph 3 under the subheading BEFORE and AFTER TRIGGERS


  The most significant difference between BEFORE and AFTER triggers is that in an AFTER trigger you are not able to modify the values about to be inserted into or updated with the table in question -- the DML has executed, and it is too late change what the DML is going to do.


Just make this as a BEFORE INSERT trigger and update the needed columns:

DELIMITER $$
CREATE TRIGGER connections_INSERT_update_connection_root_trg BEFORE INSERT ON connections 
FOR EACH ROW 
BEGIN
    IF NEW.connection_root IS NULL THEN
        NEW.connection_root = NEW.connection;
    END IF;
END $$
DELIMITER ;


GIVE IT A TRY !!!