Scope Problem with Execute? - Mailing list pgsql-general

From Rob Storrs
Subject Scope Problem with Execute?
Date
Msg-id p4CcnXS6LrS_re-jXTWcqQ@speakeasy.net
Whole thread Raw
List pgsql-general
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


pgsql-general by date:

Previous
From: James Hall
Date:
Subject: Re: Pg_hba not using local setting
Next
From: Clarence Gardner
Date:
Subject: dropped columns