Files
budget-database/postgres/functions/get_transactions_for_period.sql

44 lines
1.2 KiB
PL/PgSQL

drop function if exists public.get_transactions_for_period;
create or replace function public.get_transactions_for_period(
p_account_name text
, p_start date
, p_end date
)
returns table (
bank_name text
, account_type text
, account_number text
, account_friendly_name text
, transaction_date date
, transaction_description text
, transaction_amount numeric(8,2)
, transaction_day_of_week text
, running_bal numeric
)
LANGUAGE plpgsql
AS $$
begin
raise notice 'FUNCTION: get_transactions';
-- E'\n' is new line
raise notice 'INPUT: % p_start = %; % p_end = %;', E'\n', p_start, E'\n', p_end;
return query
select
bl.bank_name, bl.account_type, bl.account_number, bl.friendly_name as account_friendly_name
, bl.trx_date as transaction_date, bl.trx_description as transaction_description, bl.trx_amount as transaction_amount
, bl.day_of_week as transaction_day_of_week, bl.running_bal
from public.runbal bl
where
lower(bl.friendly_name) = trim(lower(p_account_name))
and bl.trx_date between p_start and p_end;
end;
$$;
GRANT EXECUTE ON function public.get_transactions_for_period(text, date, date) TO acedanger;
GRANT EXECUTE ON function public.get_transactions_for_period(text, date, date) TO budgetuser;