I have the following function in 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;
I'd like to convert this into BigQuery for the same functionality and so far I've tried:
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;
But I'm getting the following error:
Syntax error: Expected ";" but got floating point literal "0.00" at [4:16]
What is the proper command to produce the same postgres-style-function as a procedure successfully in BigQuery?