我在 postgres 中有以下功能:
create function my_function(price numeric, qty numeric, min_charge numeric, other_fee numeric) returns numeric
language plpgsql
as
$$
DECLARE
_charge numeric;
BEGIN
IF qty = 0 THEN
RETURN 0.00::numeric(19, 2);
END IF;
_charge := GREATEST(price * qty, min_charge)::numeric(19, 2);
RETURN (_charge + COALESCE(other_fee, 0.00))::numeric(19, 2);
END;
$$;
alter function my_function(numeric, numeric, numeric, numeric) owner to my_location;
我想将其转换为 BigQuery 以获得相同的功能,到目前为止我已经尝试过:
create procedure my_schema.my_function(price numeric, qty numeric, min_charge numeric, other_fee numeric)
BEGIN
IF qty = 0 THEN
RETURN 0.00::numeric(19, 2);
END IF;
_charge := GREATEST(price * qty, min_charge)::numeric(19, 2);
RETURN (_charge + COALESCE(other_fee, 0.00))::numeric(19, 2);
END;
但我收到以下错误:
Syntax error: Expected ";" but got floating point literal "0.00" at [4:16]
在 BigQuery 中成功生成与过程相同的 postgres-style-function 的正确命令是什么?