I am new to PostgresQL and having some trouble in feeding a function with a variable from an outer function. (maybe it is not possible...)
Inside a function I am trying to assign a value from calling another function like this: left_bipolar_n:=public.convert_to_decimal(left_bipolar);
When I call the function, If I use something like '122' as an argument instead of "left_bipolar" it works just fine but just as it is I get: Error: invalid input syntax for type numeric: " "
I should say that Function convert_to_decimal expects text
Complete code:
-- FUNCTION: public.AmateurExercise(numeric)
--drop FUNCTION public."AmateurExercise"(numeric);
CREATE OR REPLACE FUNCTION public."AmateurExercise"(
n numeric)
RETURNS numeric
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
declare
bipolar text;
tamanho integer;
left_bipolar text;
right_bipolar text;
left_bipolar_n numeric;
right_bipolar_n numeric;
begin
bipolar:=public.convert_to_bipolar8(n);
tamanho=length(bipolar);
if tamanho/2 =floor (tamanho/2) then
begin
left_bipolar=left(bipolar,tamanho/2);
right_bipolar=right(bipolar, tamanho/2);
end;
else
left_bipolar=left(bipolar,(tamanho-1)/2);
right_bipolar=right(bipolar, ((tamanho-1)/2)+1);
end if;
left_bipolar_n:=public.convert_to_decimal(left_bipolar);
return left_bipolar_n;
end;
$BODY$;
ALTER FUNCTION public."AmateurExercise"(numeric)
OWNER TO postgres;