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
Post a Comment