code: def subst_favorite_query_args(query, args):
      
      for idx, val in enumerate(args):
          subst_var = '$' + str(idx + 1)
          if subst_var not in query:
              return [None, 'query does not have substitution parameter ' + subst_var + ':\n  ' + query]
  
          query = query.replace(subst_var, val)
  
      match = re.search('\\$\d+', query)
      if match:
          return[None, 'missing substitution for ' + match.group(0) + ' in query:\n  ' + query]
  
      return [query, None]
docs: replace positional parameters ($1...$N) in query.