Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION PUBLIC.merge_agrio(ver NUMERIC,
- tag NUMERIC,
- blockidin NUMERIC,
- rowdatein CHARACTER VARYING,
- countnew NUMERIC,
- eventsnew NUMERIC,
- deventsnew NUMERIC,
- durationnew NUMERIC,
- devtype NUMERIC,
- placementin NUMERIC,
- unservednew NUMERIC,
- unconfirmednew NUMERIC)
- RETURNS NUMERIC
- LANGUAGE plpgsql
- AS $FUNCTION$
- DECLARE
- last_id NUMERIC;
- BEGIN
- IF ver IS NOT NULL
- THEN
- DELETE FROM R_AGRIO /*!IDX*/
- WHERE tagid = tag AND blockid = blockidin AND version < ver;
- ELSE
- ver = 1;
- END IF;
- LOOP
- UPDATE R_AGRIO/*!IDX*/
- SET
- IMPRESSIONS = IMPRESSIONS + countnew,
- count = count + eventsnew,
- dcount = dcount + deventsnew,
- duration = duration + durationNew,
- unserved = unserved + unservedNew,
- unconfirmed = unconfirmed + unconfirmedNew
- WHERE
- tagid = tag AND
- blockid = blockidin AND
- rowdate = rowdateIn AND
- device_type = devType AND
- placement = placementIn
- RETURNING id
- INTO last_id;
- IF FOUND
- THEN
- RETURN last_id;
- END IF;
- BEGIN
- INSERT INTO R_AGRIO/*!IDX*/
- (VERSION, TAGID, blockid, ROWDATE, DEVICE_TYPE, PLACEMENT, UNSERVED, UNCONFIRMED, IMPRESSIONS, count, dcount, DURATION, ID)
- VALUES
- (ver, tag, blockidin, rowdateIn, devType, placementIn, unservedNew,
- unconfirmedNew, countnew, eventsnew, deventsnew, durationNew,
- NEXTVAL('SEQAGRIO'));
- RETURN lastval();
- EXCEPTION WHEN unique_violation
- THEN
- END;
- END LOOP;
- END;
- $FUNCTION$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement