{"data":{"slug":"github-google-skills-skills-cloud-bigquery-migration-data-exporter-6fae60ca3c94","title":"Generate Type-Safe SQL Export Scripts for BigQuery Ingestion","summary":"Create schema-aligned SQL export files for Snowflake, Databricks, Teradata, Oracle, and PostgreSQL from BigQuery Migration Service metadata. The deliverable is type-safe SQL files (.sql) for data migration workflows, generated without connecting to the source database.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-exporter-6fae60ca3c94","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-exporter-6fae60ca3c94","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-exporter-6fae60ca3c94.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-exporter-6fae60ca3c94\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Before executing any command, read and follow the instructions in [Usage Attribution](references\/attribution.md). Copy the appropriate asset template from the skill's directory into your working directory. Ensure the Google Cloud CLI is installed, and authenticate with `gcloud auth login` and `gcloud auth application-default login`. Verify that your identity or service account has the required IAM roles for Cloud Storage access.","instructions":"---\nname: bigquery-migration-data-exporter\nmetadata:\n  version: \"1.0.0\"\n  category: BigDataAndAnalytics\n  publisher: google\ndescription: >-\n  Generates type-safe, schema-aligned database data export SQL files (.sql) for\n  Snowflake, Databricks, Teradata, Oracle, and PostgreSQL directly from\n  BigQuery Migration Service (BQMS) translation_output\/metadata\n  configs, exporting into target file formats (such as Parquet). Use when\n  generating source database export SQL scripts for BigQuery ingestion without\n  connecting to the source database. Don't use for executing SQL against source\n  databases or streaming\/staging exported files, extracting source database\n  catalog metadata, translating SQL queries or DDL schemas (use\n  bigquery-migration-sql-translator), loading staged Parquet files into\n  BigQuery, or running post-migration data validation.\n---\n\n# BigQuery Migration Data Exporter\n\nThis skill coordinates the generation of type-aware data export SQL scripts\n(`.sql` files) for source data warehouses (such as Snowflake, Databricks,\nTeradata, Oracle, and PostgreSQL) into target file formats (such as\n**BigQuery-aligned Parquet files**), guided by dialect and format specifications\nin the **`references\/`** directory.\n\nAll templates in this skill are **pure SQL generators with zero JDBC or database\nconnector dependencies**.\n\n> [!TIP]\n> Point directly to the BigQuery Migration Service (BQMS)\n> **`translation_output\/metadata`** directory (local path or Cloud Storage URI).\n> It automatically discovers all physical tables and target BigQuery logical\n> types from `metadata\/config\/*.yaml`.\n\n## Usage Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read and follow the instructions in\n[Usage Attribution](references\/attribution.md).\n\n## Before you begin\n\n1.  **Google Cloud CLI & Project Setup**: When reading translation outputs or\n    metadata archives from `gs:\/\/` Cloud Storage URIs, ensure the\n    [Google Cloud CLI](https:\/\/cloud.google.com\/sdk\/docs\/install) is\n    installed, verify that your Google Cloud project has an active Cloud Billing\n    account attached, and configure the target project:\n\n    ```bash\n    gcloud config set project {project_id}\n    ```\n\n2.  **Enable the API**: When reading metadata from Cloud Storage (`gs:\/\/`), ask\n    the user before enabling APIs, then enable the Cloud Storage API\n    (`storage.googleapis.com`):\n\n    ```bash\n    gcloud services enable storage.googleapis.com\n    ```\n\n3.  **Authentication & Required Identity and Access Management (IAM) Roles**:\n    Authenticate with `gcloud auth login` and `gcloud auth application-default\n    login` (or set `GOOGLE_APPLICATION_CREDENTIALS` for service account\n    authentication). Verify that your identity or service account has\n    `roles\/storage.objectViewer` (Storage Object Viewer) on any Cloud Storage\n    bucket holding input metadata. Creating a staging bucket requires\n    `roles\/storage.admin` (Storage Admin) on the Google Cloud project, and\n    deleting staged files requires `roles\/storage.objectAdmin` (Storage Object\n    Admin) on the staging bucket.\n\n4.  **Python Environment**: The generator templates require Python 3.9 or\n    later. Ask the user for confirmation before installing Python packages,\n    then install PyYAML in a virtual environment (generator templates have\n    zero JDBC or database connector dependencies):\n\n    ```bash\n    pip install pyyaml==6.0.2\n    ```\n\n5.  **Region, Cost & Cleanup**: Ask the user for confirmation before creating\n    a new Cloud Storage bucket for staging exported Parquet files (`gcloud\n    storage buckets create gs:\/\/{bucket} --location={region}`), and default to\n    `us-central1` unless your target BigQuery dataset uses another region\n    (co-locate buckets with your dataset; see\n    [Google Cloud locations](https:\/\/cloud.google.com\/about\/locations)). Review\n    [Google Cloud Pricing](https:\/\/cloud.google.com\/pricing) before staging\n    large exports. After BigQuery ingestion, temporary staged Parquet prefixes\n    can be removed with `gcloud storage rm -r gs:\/\/{bucket}\/{export_prefix}`.\n    This deletion is permanent: run it only after the user explicitly confirms\n    the exact URI, and never with an empty `{export_prefix}` (which would delete\n    every object in the bucket).\n\n6.  **Snowflake Storage Integration**: To unload Snowflake tables directly to a\n    private Cloud Storage bucket (`--stage-path 'gcs:\/\/...'`), Snowflake\n    requires a [storage integration][snowflake_gcs_integration] that grants its\n    service account access to the bucket. Ask the user for the integration name\n    and pass it with the `--storage-integration` flag, which adds a\n    `STORAGE_INTEGRATION` clause to each generated `COPY INTO` statement.\n    Unloads to a Snowflake stage (for example, `@~\/bqms_export\/` or a named\n    external stage) don't need this flag.\n\n--------------------------------------------------------------------------------\n\n## 1. Direct Consumption of Translation Output Metadata\n\n`bigquery-migration-data-exporter` consumes the native BigQuery Migration\nService (BQMS) metadata translation output:\n`translation_output\/metadata\/config\/<database>\/<schema>\/<table_name>.yaml`\n\nEach configuration file specifies:\n\n1.  `sourceName`: Fully qualified source table name.\n2.  `columns`: Source data types, precision, scale, and BigQuery target types.\n3.  Table versus view: A config with neither `externalTableName` nor\n    `externalTableDdlPath` describes a view, which is recreated as a SQL view\n    and isn't exported. The Databricks generator also honors an explicit\n    `TableType` field when present.\n\n--------------------------------------------------------------------------------\n\n## 2. Format-Guided Type-Safe Export Fundamentals\n\nA plain unguided `COPY INTO @stage FROM table` or `SELECT *` often fails during\nBigQuery ingestion (`bq load`) due to serializer discrepancies (for example,\n`VARIANT` JSON encoding, `CHAR(n)` fixed-width space padding, unbounded\nTeradata\/Oracle\/PostgreSQL `NUMBER`\/`NUMERIC` scale truncation, PostgreSQL\n`MONEY` locale currency formatting, Oracle `DATE` time-of-day components, or\ntimestamp nanosecond ticks).\n\nTo ensure zero type drift and clean BigQuery ingestion, apply type-aware\nprojections guided by the target format and dialect specifications in the\n**`references\/`** directory. While Parquet is the standard and recommended\nformat for BigQuery batch ingestion due to columnar compression and strict\ntyping, the export structure adapts based on target format requirements.\n\nFor Parquet data exports, the core rules are summarized below; the mapping\nreferences listed after them hold the full per-dialect type matrices:\n\n1.  **Session Parameters (Snowflake)**:\n\n    ```sql\n    ALTER SESSION SET TIME_OUTPUT_FORMAT = 'HH24:MI:SS.FF6';\n    ALTER SESSION SET TIMESTAMP_NTZ_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF6';\n    ALTER SESSION SET TIMESTAMP_TZ_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF6 TZHTZM';\n    ```\n2.  **Semi-Structured \/ JSON (`VARIANT`, `OBJECT`, `STRUCT`, `MAP`, `ARRAY`,\n    `JSON`, `JSONB`, `XMLTYPE`, `XML`, `UUID`, `INET`)**:\n\n    *   Snowflake: `TO_VARCHAR(col) AS col`.\n    *   Databricks \/ Spark SQL: `TO_JSON(col) AS col` for `MAP` (and for\n        `STRUCT`\/`ARRAY` when targeting `JSON` or `STRING`; native passthrough\n        `col` when targeting `RECORD`\/`ARRAY`); `CAST(col AS STRING) AS col` for\n        `VARIANT`\/`JSON`\/`INTERVAL`.\n    *   Teradata: `CAST(col AS CLOB) AS col`.\n    *   Oracle: `JSON_SERIALIZE(col RETURNING CLOB) AS col` for 21c+ native\n        `JSON`, and `XMLSERIALIZE(CONTENT col AS CLOB) AS col` for `XMLTYPE`.\n    *   PostgreSQL: `CAST(col AS TEXT) AS col` for `JSON`, `JSONB`, `XML`,\n        `UUID`, `INET`, `CIDR`, `MACADDR`, `INTERVAL`, `BIT`, and `ARRAY`.\n3.  **Decimals, Numbers, Integers & Floats**:\n\n    *   `NUMBER(p, s)` \/ `DECIMAL(p, s)` \/ `NUMERIC(p, s)` with `s > 0` \u2192\n        `CAST(col AS DECIMAL(p, s)) AS col` (or `CAST(col AS NUMBER(p, s)) AS\n        col` in Oracle, or `CAST(col AS NUMERIC(p, s)) AS col` in PostgreSQL).\n    *   Unbounded or unconstrained `NUMBER` \/ `NUMBER(*)` \/ `NUMERIC` \/\n        `DECIMAL` \u2192 `CAST(col AS DECIMAL(38, 9)) AS col` in Snowflake and\n        Teradata, `CAST(col AS NUMBER(38, 9)) AS col` in Oracle, or `CAST(col AS\n        NUMERIC(38, 9)) AS col` in PostgreSQL (supports `<= 29` integer digits\n        and `9` fractional digits by default; override scale in Teradata,\n        Oracle, and PostgreSQL by using `--unbounded-number-scale`); PostgreSQL\n        `MONEY` \u2192 `CAST(col AS NUMERIC(38, 2)) AS col`.\n    *   `TINYINT` \/ `BYTEINT` \/ `SMALLINT` \/ `INT` \/ `INTEGER` \/ `BIGINT` \/\n        `SERIAL` \u2192 `CAST(col AS BIGINT) AS col`. In Oracle, `SMALLINT` \u2192\n        `CAST(col AS NUMBER(19, 0)) AS col` and the ANSI `NUMBER(38)` aliases\n        `INT` \/ `INTEGER` \u2192 `CAST(col AS NUMBER(38, 0)) AS col`. Scale-0\n        decimals with a `TargetType` of `INT64` project as 64-bit integers;\n        the mapping references list which `NUMBER(p, 0)` \/ `DECIMAL(p, 0)`\n        precisions become 64-bit integers by default.\n    *   Databricks \/ Snowflake `FLOAT` \/ `REAL` \u2192 `CAST(col AS DOUBLE) AS col`;\n        PostgreSQL `REAL` \/ `DOUBLE PRECISION` \u2192 `CAST(col AS DOUBLE PRECISION)\n        AS col`; Oracle `BINARY_FLOAT` \/ `BINARY_DOUBLE` \/ `FLOAT(p)` \u2192\n        `CAST(col AS BINARY_DOUBLE) AS col` (widens to 64-bit IEEE-754\n        `FLOAT64`).\n4.  **Temporal (`DATE`, `TIME`, `TIMESTAMP`, `TIMESTAMP_NTZ`, `TIMESTAMP WITH\n    TIME ZONE`)**:\n\n    *   Snowflake: `CAST(col AS TIMESTAMP_NTZ(6)) AS col` and\n        `CAST(CONVERT_TIMEZONE('UTC', col) AS TIMESTAMP_NTZ(6)) AS col`.\n    *   Databricks \/ Spark SQL: `CAST(col AS TIMESTAMP) AS col` when targeting\n        `TIMESTAMP`, or leave `TIMESTAMP_NTZ` uncast when targeting BigQuery\n        `DATETIME`. `TIMESTAMP_NTZ` to `TIMESTAMP` casts (and back) use the\n        session time zone, so run the scripts in a UTC session (see the\n        [Databricks reference][databricks_map]).\n    *   Teradata: `CAST(col AS TIMESTAMP(6)) AS col`, `CAST((col AT TIME ZONE\n        'GMT') AS TIMESTAMP(6)) AS col`, and `CAST((col AT TIME ZONE 'GMT') AS\n        TIME(6)) AS col`.\n    *   Oracle: `CAST(col AS TIMESTAMP(6)) AS col` for `DATE` and\n        `TIMESTAMP(p)` (or `TRUNC(col) AS col` when `DATE` explicitly targets\n        BigQuery `DATE`), `CAST(SYS_EXTRACT_UTC(col) AS TIMESTAMP(6)) AS col`\n        for `TIMESTAMP WITH TIME ZONE`, and `CAST(SYS_EXTRACT_UTC(CAST(col AS\n        TIMESTAMP WITH TIME ZONE)) AS TIMESTAMP(6)) AS col` for `TIMESTAMP WITH\n        LOCAL TIME ZONE` (UTC, whatever the session time zone).\n    *   PostgreSQL: `CAST(col AS TIME(6)) AS col` for `TIME` and `TIMETZ`,\n        `CAST(col AS TIMESTAMP(6) WITHOUT TIME ZONE) AS col` for `TIMESTAMP\n        [WITHOUT TIME ZONE]`, and `CAST(col AS TIMESTAMP(6) WITH TIME ZONE) AS\n        col` for `TIMESTAMPTZ` \/ `TIMESTAMP WITH TIME ZONE`.\n5.  **Fixed-Width Character Padding (`CHAR(n)` \/ `NCHAR(n)` \/ `BPCHAR` \/\n    `GRAPHIC(n)`)**: `TRIM(TRAILING FROM col) AS col` (Teradata) or `RTRIM(col)\n    AS col` (Oracle and PostgreSQL) to strip fixed-width trailing pad spaces.\n6.  **Explicit Target Types**: A BigQuery `TargetType` from the BQMS config\n    (for example a schema override to `INT64`, `NUMERIC`, `DATE`, or\n    `TIMESTAMP`) wins over the source-type defaults above so the Parquet\n    column matches the BigQuery DDL. Cross-type overrides that a template\n    doesn't convert keep the default projection: `STRING`, `JSON`, and\n    `BYTES` in Oracle and Teradata (text columns stay text, binary columns\n    stay bytes, and numeric or datetime columns keep their type); `BOOL` in\n    Teradata and Oracle; `TIME` in Oracle and Databricks; `DATE` on Oracle\n    columns other than `DATE` \/ `TIMESTAMP`; and targets other than numeric\n    or `STRING` on Databricks `DECIMAL` columns. If `bq load` reports a type\n    mismatch, edit the template's `# CUSTOMIZE: Custom Type Projections`\n    hook.\n\n> [!IMPORTANT]\n> Always consult the **`references\/`** directory\n> (**[Snowflake Parquet mapping reference][snowflake_map]**,\n> **[Databricks and Spark SQL Parquet mapping reference][databricks_map]**,\n> **[Teradata Parquet mapping reference][teradata_map]**,\n> **[Oracle Parquet mapping reference][oracle_map]**, and\n> **[PostgreSQL Parquet mapping reference][postgres_map]**) to\n> verify type conversions, formatting options, and dialect-specific export\n> syntax.\n\n--------------------------------------------------------------------------------\n\n## 3. Asset Templates & Agent Workflow\n\nThis skill provides pure-Python SQL generator asset templates in `assets\/` (with\nno JDBC or warehouse driver dependencies):\n\n*   [Snowflake export SQL generator template][snowflake_exporter_template]\n    (`assets\/export_snowflake_tables_template.py`)\n*   [Databricks export SQL generator template][databricks_exporter_template]\n    (`assets\/export_databricks_tables_template.py`)\n*   [Teradata export SQL generator template][teradata_exporter_template]\n    (`assets\/export_teradata_tables_template.py`)\n*   [Oracle export SQL generator template][oracle_exporter_template]\n    (`assets\/export_oracle_tables_template.py`)\n*   [PostgreSQL export SQL generator template][postgres_exporter_template]\n    (`assets\/export_postgres_tables_template.py`)\n\n### Agent Workflow: Copy, Conditionally Customize, and Generate SQL\n\n1.  **Copy the Asset Template**: Copy `assets\/<template_name>_template.py` from\n    this skill's directory (`<SKILL_DIR>`) into your working directory (copy the\n    file; do not paste or re-type the template contents into the response).\n    `<SKILL_DIR>` is the directory containing this `SKILL.md`:\n\n    ```bash\n    # For Snowflake:\n    cp <SKILL_DIR>\/assets\/export_snowflake_tables_template.py .\/export_snowflake_tables.py\n\n    # For Databricks:\n    cp <SKILL_DIR>\/assets\/export_databricks_tables_template.py .\/export_databricks_tables.py\n\n    # For Teradata:\n    cp <SKILL_DIR>\/assets\/export_teradata_tables_template.py .\/export_teradata_tables.py\n\n    # For Oracle:\n    cp <SKILL_DIR>\/assets\/export_oracle_tables_template.py .\/export_oracle_tables.py\n\n    # For PostgreSQL:\n    cp <SKILL_DIR>\/assets\/export_postgres_tables_template.py .\/export_postgres_tables.py\n    ```\n\n2.  **Conditionally Customize Extension Points**: Run the copy as-is. Modify it\n    only if one of the following applies (prefer editing the marked `#\n    CUSTOMIZE:` sections; `# DEFAULT SCAFFOLDING` sections can be kept unchanged\n    unless deeper orchestration adjustments are needed):\n\n    *   **Custom Type Projections (`# CUSTOMIZE: Custom Type Projections`)**:\n        Adjust `format_column_cast()` in `export_snowflake_tables.py`,\n        `export_databricks_tables.py`, `export_teradata_tables.py`,\n        `export_oracle_tables.py`, or `export_postgres_tables.py` for\n        non-standard data types, custom precision bounds, or special\n        JSON\/geography serialization formats.\n    *   **Stage & Storage Configuration (`# CUSTOMIZE: Stage & Storage\n        Configuration`)**: Customize `COPY INTO` file format options\n        (`MAX_FILE_SIZE`, compression codecs, or encryption flags) in\n        `_build_copy_into_query()` or Spark SQL `INSERT OVERWRITE DIRECTORY`\n        options in `_build_insert_overwrite_query()`. Pass Snowflake storage\n        integration names with the `--storage-integration` flag instead of\n        editing the template.\n    *   **Table & Row Filtering (`# CUSTOMIZE: Table & Row Filtering` \/ `#\n        CUSTOMIZE: Row Filters`)**: Add custom `WHERE` clauses, partition\n        predicates, or custom schema\/table inclusion\/exclusion filters in\n        `_filter_tables_to_export()`, `_build_select_query()`, or\n        `load_tables_from_metadata_path()`.\n\n3.  **Generate the Export SQL Files**: Run the copied script with `python3`\n    (`python3 .\/export_snowflake_tables.py`,\n    `python3 .\/export_databricks_tables.py`,\n    `python3 .\/export_teradata_tables.py`, `python3 .\/export_oracle_tables.py`,\n    or `python3 .\/export_postgres_tables.py`) to output a unified `.sql` script\n    (`--output-sql`) and\/or per-table `*_export.sql` scripts (`--output-dir`).\n\n4.  **Check the Output**: Confirm the script exited with status `0`, report\n    any `WARNING:` lines from stderr (such as skipped duplicate tables), and\n    check that the number of `-- Unload Table:` markers (or `*_export.sql`\n    files) matches the tables you expect to export.\n\n--------------------------------------------------------------------------------\n\n### A. Snowflake Export SQL Generator (`.\/export_snowflake_tables.py`)\n\n#### 1. Generate Unified Export SQL Script (`--output-sql`)\n\nUnloading directly to Cloud Storage (`gcs:\/\/`) requires a Snowflake storage\nintegration (see [Before you begin](#before-you-begin)):\n\n```bash\npython3 .\/export_snowflake_tables.py \\\n    --translation-metadata-dir gs:\/\/my-bucket\/translation_output\/metadata\/ \\\n    --stage-path 'gcs:\/\/my-bucket\/data_unload\/' \\\n    --storage-integration my_gcs_integration \\\n    --output-sql export_snowflake_to_parquet.sql\n```\n\n#### 2. Generate Per-Table Export SQL Files (`--output-dir`)\n\n```bash\npython3 .\/export_snowflake_tables.py \\\n    --translation-metadata-dir .\/translated_output\/metadata \\\n    --stage-path '@~\/bqms_export\/' \\\n    --output-dir .\/export_sql\n```\n\nWhen the tables span more than one Snowflake database (tables whose metadata\nomits the database count as `--default-database`), the generator\nprefixes each unload subpath, `-- Unload Table:` label, and per-table file name\nwith the database (for example, `@~\/bqms_export\/<DB>\/<SCHEMA>\/<TABLE>\/`) so that\nidentically named `<SCHEMA>.<TABLE>` pairs don't overwrite each other.\n\nSnowflake resolves unquoted identifiers to uppercase, so names that aren't\nuppercase are double-quoted to keep their exact case. Pass `--default-database`\nand `--default-schema` exactly as the catalog stores them (usually uppercase,\nsuch as `ANALYTICS`).\n\n### B. Databricks Export SQL Generator (`.\/export_databricks_tables.py`)\n\nGenerates catalog-agnostic 2-part `<schema>.<table>` Spark SQL `INSERT OVERWRITE\nDIRECTORY ... USING PARQUET` (or standalone `SELECT` by using `--export-mode\nselect`) scripts (`.sql`) with explicit type-safe projections for all discovered\nDelta \/ Spark tables. Leave `--catalog` unset so the generated `.sql` files work\nacross both Unity Catalog and `hive_metastore` (activated by using `USE CATALOG`\non the target Spark or Databricks session at execution time), or pass `--catalog\n<CATALOG>` for explicit 3-part table qualification. `--catalog` also exports\nonly the tables of that catalog when the metadata names catalogs (3-part YAML\n`sourceName` values or the extractor `metadata.zip`); the generator exits with\nan error that lists the available catalogs when it matches none of them:\n\n```bash\npython3 .\/export_databricks_tables.py \\\n    --translation-metadata-dir .\/translated_output\/metadata \\\n    --stage-path '\/tmp\/databricks_export' \\\n    --output-sql export_databricks_to_parquet.sql \\\n    --output-dir .\/export_sql\n```\n\n### C. Teradata Export SQL Generator (`.\/export_teradata_tables.py`)\n\nGenerates explicit-cast Teradata `SELECT` scripts (`.sql`) with `-- Unload\nTable: <DB>.<TABLE> -> Parquet` and `-- Required Columns:` markers consumed by\ndownstream Python Parquet streaming scripts (for example, by using `teradatasql`\nand `pyarrow`). Use `--default-database <DB>` as a fallback qualifier when\nmetadata omits `TableSchema` (defaults to `$TERADATA_DATABASE`), `--database\n<DB>` (repeatable) as an allow-list filter to export only specific databases\n(the generator exits with an error when it leaves no tables),\n`--unbounded-number-scale <S>` to adjust the fractional scale for unbounded\n`NUMBER` \/ `NUMBER(*)` columns (default `9`), and `--keep-char-padding` if\nfixed-width `CHAR(n)` trailing spaces must be preserved instead of trimmed:\n\n```bash\n# 1. Generate per-table Teradata export SQL files from BQMS translation output:\npython3 .\/export_teradata_tables.py \\\n    --translation-metadata-dir .\/translated_output\/metadata \\\n    --default-database my_db \\\n    --output-dir .\/export_sql\n\n# 2. Generate a unified export SQL script from a Teradata extractor metadata.zip:\npython3 .\/export_teradata_tables.py \\\n    --metadata-zip gs:\/\/my-bucket\/teradata_metadata\/dwh-migration-teradata-metadata.zip \\\n    --database my_db \\\n    --output-sql teradata_export.sql\n```\n\n### D. Oracle Export SQL Generator (`.\/export_oracle_tables.py`)\n\nGenerates explicit-cast Oracle `SELECT` scripts (`.sql`) with `-- Unload Table:\n<SCHEMA>.<TABLE> -> Parquet` and `-- Required Columns:` markers consumed by\ndownstream Python Parquet streaming scripts (for example, by using\n`python-oracledb` and `pyarrow`). Use `--default-schema <SCHEMA>` as a fallback\nqualifier when metadata omits `TableSchema` (defaults to `$ORACLE_SCHEMA`),\n`--schema <SCHEMA>` (repeatable) as an allow-list filter to export only specific\nschemas, `--unbounded-number-scale <S>` to adjust the fractional scale for\nunconstrained `NUMBER` columns (default `9`), and `--keep-char-padding` if\nfixed-width `CHAR(n)` \/ `NCHAR(n)` trailing spaces must be preserved instead of\ntrimmed. Identifiers that aren't uppercase are double-quoted to keep their exact\ncase, so pass `--default-schema` exactly as the catalog stores it (usually\nuppercase, such as `HR`):\n\n```bash\n# 1. Generate per-table Oracle export SQL files from BQMS translation output:\npython3 .\/export_oracle_tables.py \\\n    --translation-metadata-dir .\/translated_output\/metadata \\\n    --default-schema MY_SCHEMA \\\n    --output-dir .\/export_sql\n\n# 2. Generate a unified export SQL script from an Oracle extractor metadata.zip:\npython3 .\/export_oracle_tables.py \\\n    --metadata-zip gs:\/\/my-bucket\/oracle_metadata\/dwh-migration-oracle-metadata.zip \\\n    --schema MY_SCHEMA \\\n    --output-sql oracle_export.sql\n```\n\n### E. PostgreSQL Export SQL Generator (`.\/export_postgres_tables.py`)\n\nGenerates explicit-cast PostgreSQL `SELECT` scripts (`.sql`) with `-- Unload\nTable: <SCHEMA>.<TABLE> -> Parquet` and `-- Required Columns:` markers consumed\nby downstream Python Parquet streaming scripts (for example, by using `psycopg2`\nand `pyarrow`). Use `--default-schema <SCHEMA>` as a fallback qualifier when\nmetadata omits `TableSchema` (defaults to `$PG_SCHEMA`), `--schema <SCHEMA>`\n(repeatable) as an allow-list filter to export only specific schemas,\n`--database <DB>` (repeatable) to keep only one database's tables when the\nmetadata spans several PostgreSQL databases (the generator exits with an error\nwhen `--schema` \/ `--database` leave no tables),\n`--unbounded-number-scale <S>` to adjust the fractional scale for unconstrained\n`NUMERIC` columns (default `9`), and `--keep-char-padding` if fixed-width\n`CHAR(n)` \/ `BPCHAR` trailing spaces must be preserved instead of trimmed.\nIdentifiers that aren't lowercase are double-quoted to keep their exact case,\nso pass `--default-schema` exactly as the catalog stores it (usually lowercase,\nsuch as `public`). BQMS YAML configs record PostgreSQL `NUMERIC` columns as a\n`NUMERIC(18, 0)` placeholder, so pass the extractor `--metadata-zip` together\nwith `--translation-metadata-dir` (example 3) to restore exact `NUMERIC(p, s)`\nand `NOT NULL` details:\n\n```bash\n# 1. Generate per-table PostgreSQL export SQL files from BQMS translation output:\npython3 .\/export_postgres_tables.py \\\n    --translation-metadata-dir .\/translated_output\/metadata \\\n    --default-schema public \\\n    --output-dir .\/export_sql\n\n# 2. Generate a unified export SQL script from a PostgreSQL extractor metadata.zip:\npython3 .\/export_postgres_tables.py \\\n    --metadata-zip gs:\/\/my-bucket\/postgres_metadata\/postgresql-metadata.zip \\\n    --schema public \\\n    --output-sql postgres_export.sql\n\n# 3. Combine BQMS translation output with the extractor metadata.zip:\npython3 .\/export_postgres_tables.py \\\n    --translation-metadata-dir .\/translated_output\/metadata \\\n    --metadata-zip gs:\/\/my-bucket\/postgres_metadata\/postgresql-metadata.zip \\\n    --default-schema public \\\n    --output-dir .\/export_sql\n```\n\n--------------------------------------------------------------------------------\n\n## 4. Generated SQL Pattern\n\n### Snowflake COPY INTO Pattern\n\n```sql\nALTER SESSION SET TIME_OUTPUT_FORMAT = 'HH24:MI:SS.FF6';\nALTER SESSION SET TIMESTAMP_NTZ_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF6';\nALTER SESSION SET TIMESTAMP_TZ_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF6 TZHTZM';\n\nCOPY INTO 'gcs:\/\/my-bucket\/data_unload\/RAW_POS\/MENU\/'\nFROM (\n    SELECT\n      CAST(MENU_ID AS BIGINT) AS MENU_ID,\n      CAST(COST_OF_GOODS_USD AS DECIMAL(38, 4)) AS COST_OF_GOODS_USD,\n      TO_VARCHAR(MENU_ITEM_HEALTH_METRICS_OBJ) AS MENU_ITEM_HEALTH_METRICS_OBJ\n    FROM MY_DB.RAW_POS.MENU\n  )\n  STORAGE_INTEGRATION = my_gcs_integration\nFILE_FORMAT = (\n  TYPE = PARQUET\n  COMPRESSION = SNAPPY\n)\nHEADER = TRUE\nOVERWRITE = TRUE\nMAX_FILE_SIZE = 104857600;\n```\n\n### Databricks, Teradata, Oracle, and PostgreSQL Patterns\n\nSection 4 of the [Databricks][databricks_map], [Teradata][teradata_map],\n[Oracle][oracle_map], and [PostgreSQL][postgres_map] mapping references shows\nthe complete generated script: Spark SQL `INSERT OVERWRITE DIRECTORY ... USING\nPARQUET SELECT ...` for Databricks, and explicit-cast `SELECT ...` statements\n(`LOCKING ROW FOR ACCESS SELECT ...` in Teradata) with `-- Unload Table:` and\n`-- Required Columns:` markers for the others.\n\n[snowflake_exporter_template]: assets\/export_snowflake_tables_template.py\n[databricks_exporter_template]: assets\/export_databricks_tables_template.py\n[teradata_exporter_template]: assets\/export_teradata_tables_template.py\n[oracle_exporter_template]: assets\/export_oracle_tables_template.py\n[postgres_exporter_template]: assets\/export_postgres_tables_template.py\n[snowflake_map]: references\/snowflake_parquet_mapping.md\n[databricks_map]: references\/databricks_parquet_mapping.md\n[teradata_map]: references\/teradata_parquet_mapping.md\n[oracle_map]: references\/oracle_parquet_mapping.md\n[postgres_map]: references\/postgres_parquet_mapping.md\n[snowflake_gcs_integration]: https:\/\/docs.snowflake.com\/en\/user-guide\/data-load-gcs-config\n","use_cases":["Export database tables to SQL scripts for BigQuery ingestion without connecting to the source database","Generate export scripts for multiple target databases from BQMS metadata","Create schema-aligned SQL files for data migration workflows"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/c413c1fdc1714f2e4ae44a449b9744348197119c\/skills\/cloud\/bigquery-migration-data-exporter\/SKILL.md","source_commit":"c413c1fdc1714f2e4ae44a449b9744348197119c","license":null,"version":null,"listing_approved_at":"2026-11-27","created_at":"2026-11-26T10:52:29.000000Z","updated_at":"2026-11-27T07:43:08.000000Z","seo_title":"Generate SQL Export Scripts for BigQuery Ingestion","seo_description":"Create type-safe SQL export files for Snowflake, Databricks, Teradata, Oracle, and PostgreSQL using BigQuery Migration Service metadata.","seo_keywords":["BigQuery SQL export generator","Data migration SQL scripts","Schema-aligned SQL export","BigQuery Migration Service export","Database export scripts generator"]}}