Fixes #2177 update_pm_count() can throw sql error in Postgres