refactor runbal view to include transaction ID and improve formatting

This commit is contained in:
Peter Wood
2025-09-23 15:39:57 -04:00
parent 74ef4734f7
commit 635e83a160

View File

@@ -1,22 +1,15 @@
drop view if exists public.runbal;
-- public.runbal source
create view public.runbal as
select
acct.acct_bank_name as account_bank_name,
acct.acct_type as account_type,
acct.acct_number as account_number,
acct.acct_friendly_name as account_friendly_name,
trx.trx_date as transaction_date,
trx.trx_description as transaction_description,
trx.trx_amount::numeric(8, 2) as transaction_amount,
to_char(trx.trx_date, 'day') transaction_day_of_week,
sum(trx.trx_amount) over (
partition by
trx.acct_id
order by
trx.trx_date,
trx.trx_amount desc rows unbounded preceding
) running_bal
from
public.budgetdetails trx
join public.accounts acct using (acct_id)
CREATE OR REPLACE VIEW public.runbal
AS SELECT acct.institution_name AS account_bank_name,
acct.acct_type AS account_type,
acct.acct_number AS account_number,
acct.friendly_name AS account_friendly_name,
trx.trx_date AS transaction_date,
trx.trx_description AS transaction_description,
trx.trx_amount::numeric(8,2) AS transaction_amount,
to_char(trx.trx_date::timestamp with time zone, 'day'::text) AS transaction_day_of_week,
sum(trx.trx_amount) OVER (PARTITION BY trx.acct_id ORDER BY trx.trx_date, trx.trx_amount DESC ROWS UNBOUNDED PRECEDING) AS running_bal,
trx.trx_id as transaction_id
FROM budgetdetails trx
JOIN accounts acct USING (acct_id);