I have problems with my dynamically created sql's breaking off when running into null values in the table. Look at the example underneath:

select 'insert into mytable2 (id1,id2) values ('||
id1||','||id2||');' from mytable1

this returns 3 rows

insert into mytable2 (id1,id2) values (1,2);
null
insert into mytable2 (id1,id2) values (2,3);



as you see the second row is null since the id2 value is null in that row
i fix the statement to look like this:

select 'insert into mytable2 (id1,id2) values ('||
id1||','||coalesce(cast(id2 as text),'null')||');' from mytable1

and this returns 3 rows:

insert into mytable2 (id1,id2) values (1,2);
insert into mytable2 (id1,id2) values (1,null);
insert into mytable2 (id1,id2) values (2,3);



the problem is that it will be so much work using the coalesce cast functions for every field in my sql, an i wonder if anyone has a better way of doing this.

please help, anyone!
-+rune+-