Thanks for review!
I added a regression test that is based on code from previous email
New patch is attached
Oleg Tselebrovskiy, Postgres Pro