Running the following SQL statement:
create or replace procedure test_insert_prepare2(howmany int)
language plpgsql
as $$
declare counter integer:=0;
declare note int;
begin
prepare fooplan(int) as
insert into procedure_testing_table values($1, $2);
select count(*) into strict note from procedure_testing_table;
while counter < howmany loop
counter := counter +1;
note := note +1;
execute fooplan(note,'testing_prepare');
end loop;
end;
$$
always shows an error:
ERROR: prepared statement "fooplan" already exists
How could I use prepare statement correctly in a while loop?