I have the following plpgsql code. I am trying to use r.a
as one of the fields to insert into my new table, but it returns the error that r.a
column does not exist.
create or replace function function1() returns void as $$
declare r t%rowtype;
begin
EXECUTE format('CREATE TABLE f_t(a INT, b INT)');
for r in select * from t
LOOP
EXECUTE format('INSERT INTO f_t(a, b) values (r.a, r.b)');
END LOOP;
RETURN;
end
t
's structure is also (a int,b int)
.