Your trigger is wrong. You try to insert the same row twice.
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных