I have the following script:
use my_db;
if (2 < 3) then
select 1;
end if;
When I execute this with command:
mysql --user=myuser --password=mypassword < script.sql
I get the following error:
ERROR 1064 (42000) at line 3: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if (2 < 3) then
select 1' at line 1
Can anybody explain me why this? From mysql docs found here I think it should be working fine.
if
statement is only allowed in programming blocks, such as stored procedures, user-defined functions, and triggers. Put the conditional logic in a stored procedure and call the stored procedure from the script. – Centric