Changes between Version 3 and Version 4 of WikiStart/Optimization/vtora_verzija


Ignore:
Timestamp:
04/01/25 22:04:07 (2 months ago)
Author:
203206
Comment:

db

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart/Optimization/vtora_verzija

    v3 v4  
    6464
    6565
     66=== Trigger 1
     67{{{
     68create or replace function after_transaction_trigger()
     69returns trigger as $$
     70begin
     71
     72        if new.type = 'Deposit' then
     73                insert into Deposit(account_id, transaction_id, amount)
     74                values (new.account_id, new.transaction_id, new.amount);
     75       
     76        elsif new.type = 'Withdrawal' then
     77                insert into Deposit(account_id, transaction_id, amount)
     78                values (new.account_id, new.transaction_id, new.amount);
     79       
     80        elsif new.type like '(MKD) Transfer Out to%' then
     81                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     82                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),
     83                        new.id, new.currency;
     84
     85        elsif new.type like '(USD) Transfer Out to%' then
     86                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     87                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),
     88                        new.id, new.currency;
     89       
     90        elsif new.type like '(EUR) Transfer Out to%' then
     91                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     92                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),
     93                        new.id, new.currency;
     94                       
     95        elsif new.type like '(GBP) Transfer Out to%' then
     96                insert into transferred_money(s_account_id, r_account_id, t_id, currency)
     97                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),
     98                        new.id, new.currency;
     99
     100        end if;
     101        return new;
     102end;
     103$$ language plpgsql;
     104
     105create trigger after_transaction
     106after insert on transaction
     107for each row
     108execute function after_transaction_trigger();
     109}}}
     110
    66111
    67112=== Trigger 2