Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION "public"."exists_deparment_code_interval"("dep_code_id" int4, "dep_id" int4, "typee_id" int4, "from_dt" date, "to_dt" date)
- RETURNS "pg_catalog"."bool" AS $BODY$
- DECLARE
- result boolean;
- rec record;
- BEGIN
- FOR rec IN
- SELECT
- dc.id, dc.from_dt, dc.to_dt
- FROM pim_department_code dc
- WHERE dc.department_id = dep_id and dc.type_id = typee_id and dc.id !=dep_code_id
- loop
- select overlaps(coalesce(rec.from_dt, date '01.01.0001'), coalesce(rec.to_dt, date '01.01.3000'), coalesce(from_dt, date '01.01.0001'), coalesce(to_dt, date '01.01.3000'))
- into result;
- if (result = 't') then
- return true;
- end if;
- end loop;
- return false;
- END;
- $BODY$
- LANGUAGE plpgsql VOLATILE
- COST 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement