-1

I'm trying to add a trigger that should automatically update a datetime column only if is not present a SQL variable. The trigger code is the following

delimiter |
CREATE TRIGGER update_sync_date
BEFORE UPDATE ON posts
FOR EACH ROW 
BEGIN
    IF @disable_sync_date_update IS NULL OR @disable_sync_date_update <> 1 THEN
        SET new.sync_date = CURRENT_TIMESTAMP
    END IF
END|
delimiter ;

The error that I recieve is

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END IF
END' at line 7

Thanks for helping

1 Answers1

0

I've found the solution, here is the correct code:

delimiter |
CREATE TRIGGER update_sync_date
BEFORE UPDATE ON posts
FOR EACH ROW 
BEGIN
    IF @disable_sync_date_update IS NULL OR @disable_sync_date_update <> 1 THEN
        SET new.sync_date = CURRENT_TIMESTAMP;
    END IF;
END|
delimiter ;