Rebased version of the patch.
-- Konstantin KnizhnikPostgres Professional: http://www.postgrespro.comThe Russian Postgres Company