I isolatet the problem from a much more complex query. Here the test scenario
DROP TABLE test;
CREATE TABLE test (
id integer,
description varchar(100)
DROP TABLE IF EXISTS test_tab;
CREATE TABLE test_tab (
id integer,
description varchar(100)
);
INSERT INTO test_tab(id, description) VALUES (1,'new');
INSERT INTO test_tab(id, description) VALUES (2,'new');
SELECT * from test_tab;
DO $$
DECLARE
myID test_tab.id%TYPE;
testID test_tab.id%TYPE;
cur_IDs CURSOR for select id from test_tab;
BEGIN
OPEN cur_IDs;
LOOP
FETCH cur_IDs into testID;
EXIT WHEN testID is NULL;
UPDATE test_tab SET description='test' WHERE id = testID RETURNING id into myID;
raise notice 'myID %', myID;
END LOOP;
CLOSE cur_IDs;
END$$;
DROP TABLE IF EXISTS test_tab;