Maybe assign the SQL to a string and do `sql.replace("rank", "custom_rank")`?