From c844642bfb13ea03fe888f55a6628794f2f5771a Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Sun, 5 Mar 2023 07:53:22 -0500 Subject: [PATCH] helper function to get account id from bank info --- postgres/functions/get_account_id.sql | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 postgres/functions/get_account_id.sql diff --git a/postgres/functions/get_account_id.sql b/postgres/functions/get_account_id.sql new file mode 100644 index 0000000..5e05840 --- /dev/null +++ b/postgres/functions/get_account_id.sql @@ -0,0 +1,34 @@ +drop function if exists public.get_account_id; + +create or replace function public.get_account_id( + p_bank_name varchar + , p_bank_account_number varchar +) +returns int +LANGUAGE plpgsql +AS $$ +declare + _account_id int; + +begin + +raise notice 'FUNCTION: get_account_id'; +-- E'\n' is new line +raise notice 'INPUT: % p_bank_name = %; % p_bank_account_number = %;', E'\n', p_bank_name, E'\n', p_bank_account_number; + +select acct.acct_id +into _account_id +from public.accounts acct +where + lower(acct.bank_name) = lower(p_bank_name) + and lower(acct.account_number) = lower(p_bank_account_number); + +raise notice 'RETURN VALUE: _account_id = %', _account_id; + +return _account_id; + +end; +$$; + +GRANT EXECUTE ON function public.get_account_id(varchar, varchar) TO acedanger; +GRANT EXECUTE ON function public.get_account_id(varchar, varchar) TO budgetuser;