diff --git a/e2e_test/udf/sql_udf.slt b/e2e_test/udf/sql_udf.slt index 4b4d1f1c39f7d..79cb40f2e54cc 100644 --- a/e2e_test/udf/sql_udf.slt +++ b/e2e_test/udf/sql_udf.slt @@ -81,6 +81,19 @@ create function print_add_two(INT) returns int language sql as 'select print($1 statement error failed to conduct semantic check, please see if you are calling non-existence functions create function non_exist(INT) returns int language sql as 'select yo(114514)'; +# Try to create an anonymous sql udf whose return type mismatches with the sql body definition +statement error return type mismatch detected +create function type_mismatch(INT) returns varchar language sql as 'select $1 + 114514 + $1'; + +# A valid example +statement ok +create function type_match(INT) returns varchar language sql as $$select '$1 + 114514 + $1'$$; + +query T +select type_match(114514); +---- +$1 + 114514 + $1 + # Call the defined sql udf query I select add(1, -1); @@ -189,7 +202,7 @@ create function add_sub(INT, FLOAT, INT) returns float language sql as $$select # Complex types interleaving statement ok -create function add_sub_types(INT, BIGINT, FLOAT, DECIMAL, REAL) returns real language sql as 'select $1 + $2 - $3 + $4 + $5'; +create function add_sub_types(INT, BIGINT, FLOAT, DECIMAL, REAL) returns double language sql as 'select $1 + $2 - $3 + $4 + $5'; statement ok create function add_sub_return(INT, FLOAT, INT) returns float language sql return -$1 + $2 - $3; @@ -290,6 +303,9 @@ drop function print_add_two; statement ok drop function regexp_replace_wrapper; +statement ok +drop function type_match; + # Drop the mock table statement ok drop table t1; diff --git a/src/frontend/src/handler/create_sql_function.rs b/src/frontend/src/handler/create_sql_function.rs index 4f3f7cfa0117b..9fddfdda31aa6 100644 --- a/src/frontend/src/handler/create_sql_function.rs +++ b/src/frontend/src/handler/create_sql_function.rs @@ -191,7 +191,7 @@ pub async fn handle_create_sql_function( // Check if the return type mismatches if e.return_type() != return_type { return Err(ErrorCode::InvalidInputSyntax(format!( - "return type mismatch detected\nexpected: {}\nactual: {}\nplease adjust your function definition accordingly", + "return type mismatch detected, expected: [{}] actual: [{}], please adjust your function definition accordingly", return_type, e.return_type() ))