Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace function norm_hours_millis() returns void as $$
- declare
- rec record;
- xml_chunk text;
- begin
- for rec in (select * from worker) loop
- xml_chunk := (SELECT XMLELEMENT(NAME "normHoursYearConfigList", XMLAGG(XMLELEMENT(NAME "normHoursConfig", XMLFOREST(normHours AS "normHours", periodStart AS "periodStart", periodEnd AS "periodEnd"))))
- FROM (
- SELECT dat."normHours" * 3600 * 1000 AS normHours,
- dat."periodStart" AS periodStart,
- dat."periodEnd" AS periodEnd
- FROM (SELECT xmltable.* FROM system.worker as ws, xmltable('//normHoursYearConfigList/normHoursConfig'
- passing cast(norm_hours_config as xml)
- columns
- "normHours" BIGINT,
- "periodStart" TEXT,
- "periodEnd" TEXT) where ws.id = rec.id) AS dat) AS xmldat);
- raise notice '%', xml_chunk;
- if xml_chunk <> '' then
- UPDATE SYSTEM.worker as w
- SET norm_hours_config = REGEXP_REPLACE(norm_hours_config, '<normHoursYearConfigList>(.*?)</normHoursYearConfigList>', ml_chunk)
- where w.id = rec.id;
- raise notice '% updated', rec.id;
- end if;
- end loop;
- end;
- $$ language plpgsql;
- SELECT * FROM norm_hours_millis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement