Would you mind sharing the whole script? It looks similar to this issue.
So instead of using
REPLACE PROCEDURE public.sp_test()LANGUAGE plpgsqlAS $procedure$begin
try
Does that work out?REPLACE PROCEDURE public.sp_test()LANGUAGE plpgsqlAS 'begin...end'