Is there a good reason for $subject, other than that the code is entangled with other ALTER TABLE code? The new SET DISTINCT might be equally affected.
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных