Changes between Version 1 and Version 2 of Trigger1
- Timestamp:
- 06/28/26 16:46:19 (8 hours ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Trigger1
v1 v2 30 30 LANGUAGE plpgsql 31 31 AS $$ 32 DECLARE 33 v_transaction_id INT; 32 34 BEGIN 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 34 42 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) 36 46 FROM transaction_breakdown tb 37 47 WHERE tb.transaction_id = t.transaction_id 38 48 ) 39 WHERE t.transaction_id = COALESCE(NEW.transaction_id, OLD.transaction_id);49 WHERE t.transaction_id = v_transaction_id; 40 50 41 51 RETURN NULL;
