create
or replace PROCEDURE public.update_budget_from_import (
  p_bank_name varchar,
  p_bank_account_number varchar
) LANGUAGE plpgsql as $$
declare
	_acct int;

begin

raise notice 'PROC: update_budget_from_import';
raise notice 'INPUT: % p_bank_name = %; % p_bank_account_number = %;', E'\n', p_bank_name, E'\n', p_bank_account_number;

_acct := public.get_account_id(p_bank_name, p_bank_account_number);

if _acct is null then
	raise notice 'could not get the account id';
end if;

truncate public.budgetdetails;
insert into public.budgetdetails (trx_description, trx_date, trx_amount, acct_id)
select
	description
	, cast(dt as date) as dt_converted
	, amount
	, _acct
from public.budgetimport;

end
$$;

grant
execute on PROCEDURE public.update_budget_from_import (varchar, varchar) to acedanger;

grant
execute on PROCEDURE public.update_budget_from_import (varchar, varchar) to budgetuser;