Reputation: 2769
I’m trying to copy a table’s schema to an empty table. It works for schemas with no nested records, but when I try to copy a schema with multiple nested records via this query:
SELECT * FROM [table] LIMIT 0
I get the following error:
Cannot output multiple independently repeated fields at the same time.
Upvotes: 2
Views: 315
Reputation: 172993
SELECT * FROM [table] LIMIT 0 with Allow Large Results and Unflatten Results
The drawback of above approach is that user can end up with quite a bill – as this way of copying schema will cost the whole original table scan.
Instead I would programmatically get/acquire table schema and then create table with this schema
Upvotes: 2
Reputation: 2769
BigQuery will automatically flatten all results (see docs), which won't work when you have more than one nested record. In the BigQuery UI, click on Show Options:
Then select your destination table and make sure Allow Large Results is checked and Flatten Results is unchecked:
Upvotes: 3