postgresql - SQL Trigger to Insert a row -


i'm using postgresql. these table involved in trigger:

pricing (title,publisher,period,offer,price)

  • the db has 4 tables describing magazine business.
  • the table above shows title, publisher of magazine, period (an option subscribe magazine, in months (integer), offer (a string, 'regular' or 'renew'), , price (integer).

the question:

write trigger adds new row in pricing table.  if new row inserted offer='regular', insert new row, same but: offer='renew' , price discount of 10%. 

here trigger, doesn't work:

create or replace function offer_f() returns trigger $$  begin       if(tg_op='insert')         if new.offer='regular'             insert pricing (title,pusblisher,offer,period, price)             values (new.title,new.publisher,"renew",new.period,new.price*0.9);         end if;     end if; return new;  end; $$ language plpgsql; 

this trigger itself:

create trigger reduced_offer after insert or update on pricing each row execute procedure offer_f() 

i don't know what's wrong here, , have tried replacing "after" "before" in trigger.

thanks,

alan


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -