FWIW I thought the stuff in commit 092d7ded2 might be pretty usefulgenerally.
-- Álvaro Herrera http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services