Postgresql Function Select Count Sql Statements