PostgreSQL Add/Remove triggers sample

Source: Internet
Author: User
Tags postgresql

-- defining triggers CREATE TRIGGER INSERT  on "public". vss_passenger_flow_201702 " for each ROWEXECUTEPROCEDURE " Vss_after_ Insert_flow "();
-- Delete Trigger DROP TRIGGER  on vss_passenger_flow_201702;
--Defining stored Procedures--FUNCTION:public.vss_after_insert_flow ()--DROP FUNCTION public.vss_after_insert_flow ();CREATE FUNCTION  Public. Vss_after_insert_flow ()RETURNS TriggerLANGUAGE'Plpgsql' Cost100.0VOLATILE notleakproof as$BODY $BEGIN    --Routine body goes here ...    IF EXISTS(SELECTcamera_id fromVss_passenger_hourWHEREcamera_id=new.i_camera_id and datetime =NEW.START_DT::D ate andEXTRACT (Hour fromTime=EXTRACT (Hour fromNew.start_dt::time)) Then    UPDATEVss_passenger_hourSETPassenger_in_count=Passenger_in_count+New.i_enter_num, Passenger_out_count=Passenger_out_count+New.i_leave_numWHEREcamera_id=new.i_camera_id and datetime =NEW.START_DT::D ate andEXTRACT (Hour fromTime=EXTRACT (Hour fromnew.start_dt::time); ELSE    INSERT  intoVss_passenger_hour (region_id,camera_id,datetime, Time,passenger_in_count,passenger_out_count)VALUES(New.i_area_id,new.i_camera_id,new.start_dt,to_timestamp (To_char (NEW.START_DT,'YYYY-MM-DD HH24')||': 00:00','YYYY-MM-DD HH24:MI:SS'), new.i_enter_num,new.i_leave_num); END IF; RETURN NULL;END$BODY $;ALTER FUNCTION  Public. Vss_after_insert_flow () OWNER toPostgres

PostgreSQL Add/Remove triggers sample

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.