Here is a rebased version of the patch. It includes some fixes after an off-list review by Konstantin Knizhnik.
-- Alexander KuzmenkovPostgres Professional: http://www.postgrespro.comThe Russian Postgres Company