From 635e83a1604a4533ccc5ee673fe38c6b93a249b7 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Tue, 23 Sep 2025 15:39:57 -0400 Subject: [PATCH] refactor runbal view to include transaction ID and improve formatting --- postgres/views/runbal.sql | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/postgres/views/runbal.sql b/postgres/views/runbal.sql index 4ea2726..4d2a1fb 100644 --- a/postgres/views/runbal.sql +++ b/postgres/views/runbal.sql @@ -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) \ No newline at end of file +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); \ No newline at end of file