Reputation: 1339
New create table feature has been released and I was wondering if it's possible to create 2 or more tables with one query.
I tried, but it returns error
Error: Syntax error: Unexpected keyword CREATE at [8:1]
#standardSQL
CREATE OR REPLACE TABLE newtables_test.cg1_uk
OPTIONS(
description="blah blah blah"
) AS
select 'x' as y;
CREATE OR REPLACE TABLE newtables_test.cg1_uk2
as
select 'y' as x
Any ideas? Is it even possible?
Thanks!
Upvotes: 2
Views: 5694
Reputation: 163
2 years later, still can't run multiple CREATE TABLE in one statement. The docs still list "CREATE TABLE statements must comply with the following rules: Only one CREATE statement is allowed." https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
But there is a solution. Separate the CREATE TABLE statements by using a terminating semicolon ( ; ). Example:
CREATE TABLE new_table_a AS SELECT id, c1, c2, c3 FROM t1;
CREATE TABLE new_table_b AS SELECT id, c4, c5, c6 FROM t1;
SELECT [...]
Upvotes: 3
Reputation: 14791
As per the documentation link in your question:
Only one CREATE statement is allowed.
So, looks like you cannot. Maybe someone else has a trick/workaround, but I'm not aware of any.
Upvotes: 5