how to rename a table without re creating it

前端 未结 3 588
长情又很酷
长情又很酷 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

    There is no rename option, but there is a copy operation, which uses a fast snapshot process. This doesn't incur any additional charges other than the additional cost of storage (of course you can delete the original table so you only get charged for the storage once).

    You can do this in the BigQuery by clicking on the table name and the dropdown arrow next to the table name, then selecting 'copy table'. Alternately you can use the bq cp command in the bq command-line tool.

    0 讨论(0)
  • 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
    )'
    

    0 讨论(0)
  • 2020-12-18 19:55

    Well you can rename a table like this.

    RENAME TABLE tb1 TO tb2, tb3 TO tb4;

    0 讨论(0)
提交回复
热议问题