postgresql - Creating a trigger and function in CartoDB -


i trying create trigger , function in cartodb uses postgresql. want trigger fire each time insert happens on table obs. want function update value in 2 other tables inland , coastal. far have tried code:

create function inlanddisp()   returns trigger $$   begin      update inland set lt_dispatch_level = obs.named_lt_dispatch_level         obs         obs.created_at = (select max(created_at) obs)         , inland.cartodb_id = 1 end;   $$ 

create trigger update_inland   after insert obs   on inland   each row   execute procedure inlanddisp();   

how can setup function , trigger work properly? getting syntax error @ or near "create".

you missing language being used in function closing semicolon. trigger, need specify table event occurring. function contain action need happen, in case updating other 2 tables.

try this:

create function inlanddisp() returns trigger $$  begin  update inland set lt_dispatch_level = obs.named_lt_dispatch_level obs obs.created_at = (select max(created_at) obs) , inland.cartodb_id = 1;  (put other query update coastal here)  return null;  end; $$ language plpgsql;   create trigger update_inland after insert  on obs each row execute procedure inlanddisp();  

refer trigger procedure guide.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -