Finally returning to this .. rebased and updated per feedback. I'm not sure of a good place to put test cases for this..
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных