Postgresql Function Select Count Into Variable Cost