The following is the definition of a working function I have in a postgres db:
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;
But when I try the following in BigQuery:
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;
""";
I get the following error:
Routine name "my_function" missing dataset while no default dataset is set in the request.
What is the command/syntax I am missing? I don't see a lot of documentation with concrete sql on how to correct for this.
Update: So far I have the following BigQuery I think is on the right track but it still gives errors for floating point literal 0.00 and other incompatible syntaxes
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;