Here’s the code I’m trying to use to create a trigger:
-- Dumping structure for trigger kavanga_lead.click_links_insert
DROP TRIGGER IF EXISTS `click_links_insert`;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='';
DELIMITER //
CREATE TRIGGER `click_links_insert` AFTER INSERT ON `click_links` FOR EACH ROW BEGIN
INSERT INTO actions_log
(
`uid`,
`table`,
`action`,
`new`
)
VALUES
(
@user_id,
'click_links',
'insert',
concat(NEW.id ,'|', NEW.`contents`, '|', NEW.channel_id, '|', NEW.name, '|', NEW.hidden, '|', if(NEW.prefix_id is null,'',NEW.prefix_id) '|', if(NEW.postfix_id is null,'',NEW.postfix_id))
);
END//
DELIMITER ;
SET SQL_MODE=@OLD_SQL_MODE;
I keep getting an error (1583) Incorrect parameters in the call to concat.
It works well if I don’t use if(NEW.prefix_id is null,'',NEW.prefix_id) but just a NEW.prefix_id. But this field can be null, so all concat‘s result becomes null to.
So, the question is how can I use IF staments inside CONCAT call?
that’s because you forgot one
commaafterif(NEW.prefix_id is null,'',NEW.prefix_id)try: