I am trying to write a For loop like this:
DO
$$
DECLARE
rec TEXT ;
rec1 record ;
BEGIN
FOR rec IN
select my_schema_name from public.table1
loop
PERFORM set_config('search_path', rec,false);
execute 'select * from table2 where status = 'NEW' into rec1' ;
RAISE NOTICE 'Record is : %', rec1;
END LOOP;
END;
$$
LANGUAGE plpgsql;
But I am getting the Syntax error :
ERROR: syntax error at or near "' into rec1'"
Can some one help me with the correct syntax of writing a Select statement having a WHERE clause with execute in the For loop.