Use custom SQL function and query.