Fixes postgresql count query