Как итерировать полученный select запрос. select запрос возвращает id ники.
for cnt in select distinct his.court_case_id
....
loop
cnt не идет по итерации, походу возрвращает просто последний элемент.
CREATE OR REPLACE FUNCTION cc_case_claim_essence()
RETURNS TABLE(val_1 text, val_2 text, val_3 text, val_4 text, val_5 text, val_6 text, val_7 text, val_8 text, val_9 text, val_10 text, val_11 text, val_12 text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
DECLARE age_array int []:= '{1767, 842}';
DECLARE cases int;
DECLARE cnt int;
DECLARE var int [];
BEGIN
-- DROP TABLE IF EXISTS upd;
for cnt in select distinct his.court_case_id
from cc_case_claim_essence as cl
inner join court_case_history his
on his.court_case_id = cl.case_id
inner join cc_penalty cp
on his.penalty_id = cp.id
where cl.case_id = his.court_case_id
and cp.delivery_date is not null
and his.case_status_id = 27
and cp.delivery_date is not null
and his.is_delete = false
loop
Update cc_case_claim_essence
set
result_proceeding_id = cp.result_proceeding_id,
essence_solution_id = cp.essence_solution_id,
delivery_time = cp.delivery_date
from cc_case_claim_essence as cl
inner join court_case_history his
on his.court_case_id = cl.case_id
inner join cc_penalty cp
on his.penalty_id = cp.id
where cl.case_id = cnt
and cp.delivery_date is not null
and his.case_status_id = 27
and cp.delivery_date is not null
and his.is_delete = false;
end loop;
END
$BODY$;
ALTER FUNCTION cc_case_claim_essence()
OWNER TO postgres;