Postgresql Function Select Count Sql Syntax