original_docstring: 
      Split the sql for a given model into a list of separate CTEs.
      :param dialect: SQL Dialect
      :param compiler_cache: Dictionary mapping model hashes to already compiled results
      :param model:
      :param reference_names: mapping of references in the raw sql, to the names of the CTEs that they refer
      :return:
      
docstring: Split the sql for a given model into a list of separate CTEs.
docstring_tokens: Split the sql for a given model into a list of separate CTEs .
code: def _single_model_to_sql(dialect: Dialect,
                           compiler_cache: Dict[str, List[SemiCompiledTuple]],
                           model: SqlModel,
                           reference_names: Dict[str, str]
                           ) -> List[SemiCompiledTuple]:
      """
      Split the sql for a given model into a list of separate CTEs.
      :param dialect: SQL Dialect
      :param compiler_cache: Dictionary mapping model hashes to already compiled results
      :param model:
      :param reference_names: mapping of references in the raw sql, to the names of the CTEs that they refer
      :return:
      """
      if model.hash in compiler_cache:
          return compiler_cache[model.hash]
      sql = model.sql
      # If there are any format strings in the placeholder values that need escaping, they should have been
      # escaped by now.
      # Otherwise this will cause trouble the next time we call format() below for the references
      sql = _format_sql(sql=sql, values=model.placeholders_formatted, model=model)
      # {{id}} (==REFERENCE_UNIQUE_FIELD) is a special placeholder that gets the unique model identifier,
      # which can be used in templates to make sure that if a model gets used multiple times,
      # the cte-names are still unique.
      _reference_names = dict(**reference_names)
      _reference_names[REFERENCE_UNIQUE_FIELD] = model.hash
      sql = _format_sql(sql=sql, values=_reference_names, model=model)
      ctes = raw_sql_to_selects(sql)
      result: List[SemiCompiledTuple] = []
      for cte in ctes[:-1]:
          # For all CTEs the name should be set. Only for the final select (== cte[-1]) it will be None.
          assert cte.name is not None
          result.append(
              SemiCompiledTuple(quoted_cte_name=quote_identifier(dialect, cte.name), sql=cte.select_sql)
          )
      result.append(
          SemiCompiledTuple(quoted_cte_name=model_to_quoted_name(dialect, model), sql=ctes[-1].select_sql)
      )
  
      compiler_cache[model.hash] = result
      return result
code_tokens: def _single_model_to_sql ( dialect : Dialect , compiler_cache : Dict [ str , List [ SemiCompiledTuple ] ] , model : SqlModel , reference_names : Dict [ str , str ] ) -> List [ SemiCompiledTuple ] : if model . hash in compiler_cache : return compiler_cache [ model . hash ] sql = model . sql sql = _format_sql ( sql = sql , values = model . placeholders_formatted , model = model ) _reference_names = dict ( ** reference_names ) _reference_names [ REFERENCE_UNIQUE_FIELD ] = model . hash sql = _format_sql ( sql = sql , values = _reference_names , model = model ) ctes = raw_sql_to_selects ( sql ) result : List [ SemiCompiledTuple ] = [ ] for cte in ctes [ : - 1 ] : assert cte . name is not None result . append ( SemiCompiledTuple ( quoted_cte_name = quote_identifier ( dialect , cte . name ) , sql = cte . select_sql ) ) result . append ( SemiCompiledTuple ( quoted_cte_name = model_to_quoted_name ( dialect , model ) , sql = ctes [ - 1 ] . select_sql ) ) compiler_cache [ model . hash ] = result return result
short_docstring: Split the sql for a given model into a list of separate CTEs.
short_docstring_tokens: Split the sql for a given model into a list of separate CTEs .
comment: """
      Split the sql for a given model into a list of separate CTEs.
      :param dialect: SQL Dialect
      :param compiler_cache: Dictionary mapping model hashes to already compiled results
      :param model:
      :param reference_names: mapping of references in the raw sql, to the names of the CTEs that they refer
      :return:
      """$SEP$# If there are any format strings in the placeholder values that need escaping, they should have been$SEP$# escaped by now.$SEP$# Otherwise this will cause trouble the next time we call format() below for the references$SEP$# {{id}} (==REFERENCE_UNIQUE_FIELD) is a special placeholder that gets the unique model identifier,$SEP$# which can be used in templates to make sure that if a model gets used multiple times,$SEP$# the cte-names are still unique.$SEP$# For all CTEs the name should be set. Only for the final select (== cte[-1]) it will be None.