I am having problem there. see what happens
sqlstr := 'insert into test(c1, c2) values ('||COALESCE(rec.c1,'NULL')||',' ||'\''||rec.c2||'\')';
You are preparing a string, so make sure you have strings everywhere:
sqlstr := 'insert into test(c1, c2) values ('||COALESCE(rec.c1::text,'NULL')||','||'\''||rec.c2||'\')';
Regards, Tomasz Myrta
---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend