postgis count sql fixed due to inheritances