--
-- get_func_drop_command/1
--
create or replace function get_func_drop_command(
character varying
) returns varchar as $$
declare
fname alias for $1;
nargs integer default 0;
v_pos integer;
v_funcdef text;
v_args varchar;
v_one_arg varchar;
v_one_type varchar;
v_nargs integer;
begin
v_funcdef := 'drop function ' || fname || '(';
select proargtypes, pronargs
into v_args, v_nargs
from pg_proc
where proname = fname::name;
v_pos := position(' ' in v_args);
while nargs < v_nargs loop
nargs := nargs + 1;
if nargs = v_nargs then
v_one_arg := v_args;
v_args := '';
else
v_one_arg := substr(v_args, 1, v_pos - 1);
v_args := substr(v_args, v_pos + 1);
v_pos := position(' ' in v_args);
end if;
select case when nargs = 1
then typname
else ',' || typname
end into v_one_type
from pg_type
where oid = v_one_arg;
v_funcdef := v_funcdef || v_one_type;
end loop;
v_funcdef := v_funcdef || ')';
return v_funcdef;
end;$$ language plpgsql;