code: def _create_table_as(
      *,
      session,
      dialect_name: str,
      source_query: Query,
      target_table_name: str,
      source_table_name: str,
  ):
      """
      Create a new table with rows from query.
  
      We have to handle CTAS differently for different dialects.
      """
      if dialect_name == "mysql":
          # MySQL with replication needs this split in to two queries, so just do it for all MySQL
          # ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
          session.execute(
              text(
                  f"CREATE TABLE {target_table_name} LIKE {source_table_name}"
              )
          )
          session.execute(
              text(
                  f"INSERT INTO {target_table_name} {source_query.selectable.compile(bind=session.get_bind())}"
              )
          )
      else:
          # Postgres and SQLite both support the same "CREATE TABLE a AS SELECT ..." syntax
          select_table = source_query.selectable.compile(
              bind=session.get_bind()
          )
          session.execute(
              text(
                  f"CREATE TABLE {target_table_name} AS {select_table}"
              )
          )
  
imports: from __future__ import annotations
  import contextlib
  import enum
  import json
  import logging
  import os
  import sys
  import time
  import warnings
  from dataclasses import dataclass
  from tempfile import gettempdir
  from typing import TYPE_CHECKING, Callable, Generator, Iterable
  from sqlalchemy import Table, and_, column, delete, exc, func, inspect, literal, or_, select, table, text, tuple_
  import airflow
  from airflow import settings
  from airflow.configuration import conf
  from airflow.exceptions import AirflowException
  from airflow.models import import_all_models
  from airflow.utils import helpers
  from airflow.utils.session import NEW_SESSION, create_session, provide_session
label_desc: Use image node_id 23 for calling a global function with example usage: _create_table_as() without return types