Pass variable as an input argument to a function inside another function in PostgreSQL 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 &quot;left_bipolar&quot; it works just fine but just as it is I get:
Error: invalid input syntax for type numeric: &quot;  &quot;
I should say that Function convert_to_decimal expects text
Complete code:
-- FUNCTION: public.AmateurExercise(numeric)
--drop FUNCTION public.&quot;AmateurExercise&quot;(numeric);

CREATE OR REPLACE FUNCTION public.&quot;AmateurExercise&quot;(
    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.&quot;AmateurExercise&quot;(numeric)
    OWNER TO postgres;
answer from a jjanes comment:
&quot;The error indicates that for some reason left_bipolar contains a space just before the call. I guess convert_to_bipolar8 must put the space there. But we can't see the code for it, not what input you called the outer function with&quot;