I am building a procedure, where I`m first creating a select statement and store it in an VARCAHR variable. I now want to execute that query and store the whole result set in an variable to loop through it or use directly in a for loop. I only find examples where the Select is hard written in the for loop definition. How do i exchange the Select statement with my variable that holds my select statement?
for r IN (SELECT ... FROM ...)
loop
--do sth;
end loop;
how i want to use it :
statement := 'SELECT .... FROM ...';
for r IN (statement) -- HOW TO DO THIS
loop
--do sth;
end loop;
EXECUTEstatement in Pl/PgSQL...