Why does my trigger in HeidiSql not inser any information?

DELIMITER //
CREATE OR REPLACE TRIGGER tmVideo
    BEFORE INSERT ON messages 
    FOR EACH ROW 
    BEGIN 
        DECLARE vurl VARCHAR(256);
        SET vurl = (SELECT url FROM videos WHERE videoId = NEW.mVideoId);
        IF new.mvideoId != NULL THEN INSERT INTO messagesvideos (messageId, videoId, url) VALUES (NEW.messageId, NEW.mvideoId, vurl);
        END IF;
    END //
DELIMITER ;

I'm trying to save on the messagesvideos table all the messages that contain a video. I created this trigger but when I do the insert on the messages table I get no response.

Upvotes: 1

Views: 238

Answers (1)

Mureinik
Mureinik

Reputation: 311853

null is not a value, it's the lack thereof. You can't use = or != to test for it, you should use the is operator instead:

IF new.mvideoId IS NOT NULL THEN 
    -- Here ----^
    INSERT INTO messagesvideos (messageId, videoId, URL)
    VALUES (NEW.messageId, NEW.mvideoId, vurl);
END IF;

Upvotes: 1

Related Questions