Postgresql Function Select Count Distinct