sqlgoogle-bigquery

Create Table As... with no data in BigQuery


I am using the following query to load data from a file into a table:

$ bq query --nouse_legacy_sql 'CREATE TABLE `AZ-163219.bqtesting.%s` 
  AS select * from `AZ-163219.bqtesting.%s_tmp

How would I create an empty table using the above query? For other reasons, I need to create the table from the file, but I'd like to load the data (in chunks) using an update statement later on.


Solution

  • Use LIMIT 0:

    $ bq query --nouse_legacy_sql '
        CREATE TABLE \`AZ-163219.bqtesting.%s\` AS
        SELECT * FROM \`AZ-163219.bqtesting.%s_tmp\`
        LIMIT 0'