It seems like we may use single overloaded function in SQL and also remove some code duplication internally.