cshin9
cshin9

Reputation: 1490

CREATE TABLE on BigQuery?

How do I create a table on BigQuery from another existing table?

For example, I have a table:

col_1, col_2, val
...  , ...  , ...

And I want to create a new table as:

CREATE TABLE new_table AS (
SELECT col_1, SUM(val) AS sum_val FROM old_table) WITH DATA;

However, I cannot first query the result and then save the result because the result is too large.

Upvotes: 1

Views: 13126

Answers (3)

Indrajeet Gour
Indrajeet Gour

Reputation: 4490

Another way to make copy of existing table of Big query to new table there, just do

select * from [source_tbl_name]

Run it, just above right-hand side you can find "save as table" button.

Click it and give the new table name. Your table will be created.

I used this to do the sampling from my bigger dataset for testing purpose.

Hope this will help.

Upvotes: 2

Dennis
Dennis

Reputation: 1169

Couldn't you do something like:

CREATE TABLE new_table AS
    (SELECT col_1, SUM(val) AS sum_val
     FROM   old_table
     GROUP BY something
     WHERE 1 > 2
     );
INSERT INTO new_table
    (SELECT col_1
          , SUM(val) AS sum_val
     FROM   old_table
     GROUP BY something
     );

(I noticed you are summing without a GROUP BY, so I fixed that bit for you (sort of).)

The CREATE TABLE would create the structure only (due to the 1>2 bit). Then you could INSERT directly.

Upvotes: -4

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172994

You should just use SELECT with respective destination parameters

SELECT col_1, SUM(val) AS sum_val FROM old_table

If you are doing this from within Web Ui - they are "under" Show Options button
enter image description here

If you are using API - check configuration.query for respective properties

Upvotes: 7

Related Questions