Changes between Version 1 and Version 2 of Trigger1


Ignore:
Timestamp:
06/28/26 16:46:19 (8 hours ago)
Author:
211101
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Trigger1

    v1 v2  
    3030LANGUAGE plpgsql
    3131AS $$
     32DECLARE
     33    v_transaction_id INT;
    3234BEGIN
    33     UPDATE transaction t
     35    IF TG_OP = 'DELETE' THEN
     36        v_transaction_id := OLD.transaction_id;
     37    ELSE
     38        v_transaction_id := NEW.transaction_id;
     39    END IF;
     40
     41    UPDATE "transaction" t
    3442    SET net_amount = (
    35         SELECT COALESCE(SUM(tb.earned_amount - tb.spent_amount), 0)
     43        SELECT COALESCE(SUM(
     44            COALESCE(tb.earned_amount, 0) - COALESCE(tb.spent_amount, 0)
     45        ), 0)
    3646        FROM transaction_breakdown tb
    3747        WHERE tb.transaction_id = t.transaction_id
    3848    )
    39     WHERE t.transaction_id = COALESCE(NEW.transaction_id, OLD.transaction_id);
     49    WHERE t.transaction_id = v_transaction_id;
    4050
    4151    RETURN NULL;