Pošto uvek zaboravim kako ide kurzor u postgresu ostaviću sebi ovde realan primer koji se može pokrenuti u pgAdminu:
DO $$ declare _c record; _ident varchar; begin for _c in select distinct nd.id,nd.fk_national, nd.nt_name, nd.nt_ident, nd.cd_national_phase, ldp.lk_desc, ass.fk_assembly, a.a_name from rbt.national_data nd inner join lookup_det ldp on ldp.id=nd.cd_national_phase inner join rbt.assembly_state ass on ass.fk_national=nd.fk_national and nd.cd_national_phase=ass.cd_national_phase inner join rbt.assembly a on ass.fk_assembly=a.id where nd.status=1003 and ass.status=1003 order by 2, 5 loop _ident := _c.nt_name || '-' || _c.lk_desc || '-' || _c.a_name; INSERT INTO rbt.heat_transfer_losses(created_by, htl_name, htl_ident, status, fk_assembly, fk_national_data, htl_value) VALUES (1, _ident, _ident, 1003, _c.fk_assembly, _c.id, 0); raise notice '%', _ident; end loop; end $$;