mirror of
https://github.com/acedanger/budget-database.git
synced 2025-12-06 07:00:14 -08:00
35 lines
719 B
PL/PgSQL
35 lines
719 B
PL/PgSQL
CREATE OR REPLACE PROCEDURE public.update_budget_from_import()
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
declare
|
|
_acct int;
|
|
|
|
begin
|
|
|
|
select acct.acct_id
|
|
into _acct
|
|
from public.accounts acct
|
|
where
|
|
lower(acct.bank_name) = 'bank of america'
|
|
and acct.account_number = '4581';
|
|
|
|
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() TO acedanger;
|
|
GRANT EXECUTE ON PROCEDURE public.update_budget_from_import() TO budgetuser;
|