Postgresql Trigger Insert Sql Conditional Count