I have a similar problem that I raised here (see link) but I don't have
the solution yet.
I received several ideas, but so far not a solution that would actually
work for me.
You may want to give the function that you find in this thread a try.
It didn't work for me, but maybe it will for you - let me know please
if it does, I am still looking for an answer.
http://groups.google.com/group/pgsql.general/browse_thread/thread/20aed89ab0e19e3d/4771fb1be397afea#4771fb1be397afea
Regards,
Balázs