where_sql is generic, move it to sql_functions