TIMELINES_ARRAY
This commit is contained in:
parent
d45a8140c0
commit
89ac7987db
@ -130,6 +130,35 @@ END;
|
||||
$$
|
||||
LANGUAGE plpgsql IMMUTABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION TIMELINES_ARRAY (sim INT8)
|
||||
RETURNS INT[]
|
||||
AS $$
|
||||
DECLARE
|
||||
timelines INT[] := '{}';
|
||||
timelines_json JSONB;
|
||||
item JSONB;
|
||||
temp_months INT;
|
||||
i INT;
|
||||
BEGIN
|
||||
timelines_json := vd.TIMELINES_JSON(sim);
|
||||
|
||||
FOR item IN SELECT * FROM json_array_elements(timelines_json::JSON) LOOP
|
||||
temp_months = (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'YYYY')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'YYYY')::INT) * 12
|
||||
+ (TO_CHAR((item->>'service_end_at')::TIMESTAMP, 'MM')::INT - TO_CHAR((item->>'service_start_at')::TIMESTAMP, 'MM')::INT);
|
||||
i := 0;
|
||||
|
||||
RAISE NOTICE 'TIMELINES_ARRAY: % - % - %', item->>'sim', item->>'package_id', temp_months;
|
||||
|
||||
WHILE i <= temp_months LOOP
|
||||
timelines := timelines || TO_CHAR((item->>'service_start_at')::TIMESTAMP + (i || ' month')::INTERVAL, 'YYYYMM')::INT;
|
||||
i := i + 1;
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
RETURN timelines;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql IMMUTABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION FIX_ORDER_COUNTS ()
|
||||
RETURNS BOOLEAN
|
||||
AS $$
|
||||
|
Loading…
x
Reference in New Issue
Block a user