mirror of
https://github.com/acedanger/budget-database.git
synced 2025-12-05 22:50:13 -08:00
helper function to get account id from bank info
This commit is contained in:
34
postgres/functions/get_account_id.sql
Normal file
34
postgres/functions/get_account_id.sql
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user