-- preparing the context:

create database boog;
use boog;

-- Define functions in non-strict mode:
set sql_mode="";

-- function t1 and t2 should calculate the same results; they only differ
-- in the IF(,,,) assuming IF(cc, aa, bb) === IF(NOT cc, bb, aa):
create function t1_tolrnt(JJ text) returns text return IF(JJ!="", JSON_TYPE(JJ), "NOPE");
create function t2_tolrnt(JJ text) returns text return IF(JJ="", "NOPE", JSON_TYPE(JJ));

-- function t3 checks the IF-operand before actually doing the IF:
create function t3_tolrnt(s text) returns text return case when s not regexp "^[0-9]+$" then s else if(s, "Y", "N") end;

-- Define the same functions in strict mode:
set sql_mode="strict_all_tables";

create function t1_strict(JJ text) returns text return IF(JJ!="", JSON_TYPE(JJ), "NOPE");
create function t2_strict(JJ text) returns text return IF(JJ="", "NOPE", JSON_TYPE(JJ));
create function t3_strict(s text) returns text return case when s not regexp "^[0-9]+$" then s else if(s, "Y", "N") end;

-- Now for the checks:
select t1_tolrnt("");
-- this result is expected

select t2_tolrnt("");
-- this result is expected

select t3_tolrnt("a");
-- this result is expected

select t1_strict("");
-- this result is expected

select t2_strict("");
-- this result is NOT expected. The expected result is "NOPE"
-- This behaviour is at least inconsistent because t1_strict() calculates the same thing without errors.

select t3_strict("a");
-- this result is NOT expected. The expected result is "a".
