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;