With thanks to a suggestion by David G. Johnston, I've attached another revised version
of the function that hopefully eliminates the problem reported by Daniel Verite.
This version also handles CamelCase schemas and tables better.
If anyone else finds a problem, kindly attach a dump of the schema to duplicate the problem.