create table kpdl_zp_nas_diff as SELECT ogc_fid, wkb_geometry, kd_kanwil, nm_kanwil, nm_kpp, kd_kpp, kd_unit_or, no_urut, nip_ar, nm_ar, seksi, zona, wil_induk, null as attribute1 FROM zp_nas; update kpdl_zp_nas_diff a set wkb_geometry = ST_Multi(COALESCE( ST_Difference(a.wkb_geometry, (SELECT ST_Union(wkb_geometry) FROM zp_nas AS b WHERE ST_Intersects(a.wkb_geometry, b.wkb_geometry) and a.ogc_fid> b.ogc_fid)), a.wkb_geometry )); with zonaolah as (select ogc_fid, --unique id cardinality(string_to_array(wil_induk::varchar, ',')) / 2 as jml_pecahan, REGEXP_REPLACE((string_to_array(wil_induk::varchar, ','))[2],'"|}|{|\s{2,}','', 1, 0, 'i') as nama_kel_pertama from zp_nas) update kpdl_zp_nas_diff a set attribute1 = initcap(a.zona) || case when zonaolah.jml_pecahan = 1 then ' dari kelurahan ' || zonaolah.nama_kel_pertama when zonaolah.jml_pecahan > 1 then ' dari kelurahan ' || zonaolah.nama_kel_pertama || ' dan ' || zonaolah.jml_pecahan - 1 || ' lainnya' else '' end from zonaolah where a.ogc_fid = zonaolah.ogc_fid; update KPDL_ZP_NAS_DIFF SET