MySQL Forums
Forum List  »  Triggers

Dynamic SQL in Triggers
Posted by: Frederic Steinfels
Date: November 17, 2019 03:09PM

I wanted to use dynamic sql in triggers. I had to figure out that this feature is disabled/broken/prohibited/not implemented. Other DB systems are said to support this. Are there any plans to fix this?

The problem at hand: I want to have a dynamic list of tablenames and rownames that I want to log. Something like this:

SET @s = CONCAT("SELECT 1 INTO res WHERE NEW.`",this,"`<=>OLD.`",this,"`");
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

IF (res=1) THEN
INSERT INTO `adminmessages` SET `message`=CONCAT(this," has changed");
END IF;

For now, I will have to hardcode all rows I want to log. Very ugly.

Options: ReplyQuote


Subject
Views
Written By
Posted
Dynamic SQL in Triggers
1244
November 17, 2019 03:09PM
557
November 17, 2019 08:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.