yes, this could get called on quite large tables (maybe not billions ...). The second solution looks useful - I'll try it on some test data. thanks both of you.
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных