how to rename a table without re creating it

前端 未结 3 595
长情又很酷
长情又很酷 2020-12-18 18:53

I didn\'t find a RENAME option to alter table name. I have a case that I must rename a table, and the only way is to select with result to new table. this query cost money,

3条回答
  •  别那么骄傲
    2020-12-18 19:32

    Use except function to rename your dataset

    bq query --destination_table practiceDataset.test_sales_orc --replace --use_legacy_sql=false 'SELECT
       * EXCEPT(
        _col16 ),
        _col16 as ingestion_tsp
      FROM (
        SELECT
            * EXCEPT(
                _col0,
                _col1,
                _col2,
                _col3,
                _col4,
                _col5,
                _col6,
                _col7,
                _col8,
                _col9,
                _col10,
                _col11,
                _col12,
                _col13,
                _col14,
                _col15),
                _col0 as order_number,
                _col1 as order_line_number,
                _col2 as version,
                _col3 as order_date,
                _col4 as extamt,
                _col5 as quantity,
                _col6 as vlucost,
                _col7 as model_number,
                _col8 as credit_amount,
                _col9 as written_sales,
                _col10 as product_category,
                _col11 as product_category_code,
                _col12 as product_class,
                _col13 as description_model,
                _col14 as location_code,
                _col15 as location_description
         FROM practiceDataset.sales_data
    )'
    

提交回复
热议问题