Changes between Version 5 and Version 6 of WikiStart/DB


Ignore:
Timestamp:
03/22/25 20:34:56 (2 months ago)
Author:
203206
Comment:

trigger

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart/DB

    v5 v6  
    6262== Triggers
    6363
     64{{{
     65create or replace function after_transaction_trigger()
     66returns trigger as $$
     67begin
     68
     69        if new.type = 'Deposit' then
     70                insert into Deposit(account_id,amount, timestamp)
     71                values (new.account_id, new.amount, new.timestamp);
     72       
     73        elsif new.type = 'Withdrawal' then
     74                insert into Withdraw(account_id,amount, timestamp)
     75                values (new.account_id, new.amount, new.timestamp);
     76       
     77        elsif new.type like '(MKD) Transfer Out to%' then
     78                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     79                select new.account_id, (select id from account where username = trim(substring(new.type from position('Transfer Out to ' in new.type)+15)) limit 1),
     80                        new.id, 'MKD';
     81
     82        elsif new.type like '(USD) Transfer Out to%' then
     83                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     84                select new.account_id, (select id from account where username = trim(substring(new.type from position('Transfer Out to ' in new.type)+15)) limit 1),
     85                        new.id, 'USD';
     86       
     87        elsif new.type like '(EUR) Transfer Out to%' then
     88                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     89                select new.account_id, (select id from account where username = trim(substring(new.type from position('Transfer Out to ' in new.type)+15)) limit 1),
     90                        new.id, 'EUR';
     91                       
     92        elsif new.type like '(GBP) Transfer Out to%' then
     93                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     94                select new.account_id, (select id from account where username = trim(substring(new.type from position('Transfer Out to ' in new.type)+15)) limit 1),
     95                        new.id, 'GBP';
     96
     97        end if;
     98        return new;
     99end;
     100$$ language plpgsql;
     101
     102create trigger after_transaction
     103after insert on transaction
     104for each row
     105execute function after_transaction_trigger()
     106
     107}}}
    64108
    65109