Thread: Scope Problem with Execute?

Scope Problem with Execute?

From
Rob Storrs
Date:
I have encountered what I think is a scoping problem with an EXECUTE
statement.

     for test_record in select * from source_table
         LOOP
         for i in 0..9 loop
              column_name := ''test_record.field_''||i;
              insert_str := ''insert into output_table (output)
                    values (''||column_name||'')'';
              execute insert_str;
         end loop;
     end loop;

I keep getting errors about not being able to find "test_record".

I can't find the right syntax so that the execute command can reference
the record (test_record).  I've tried wrapping column_name in
quote_ident(), pulling out test_record into the insert_str literal,
splitting the record.field and quote_ident() both of them.

Any help would be greatly appreciated.  Postgresql 7.2.3 on RedHat Linux
7.2 on Intel.

Thanks.
~Rob Storrs