Reputation: 25
I have created a big query table with a schema through browser tool.Next time i am appending a csv to that table through API calls from my local.But that csv don't contain all columns that i already specified. So i am getting the error "Provided Schema does not match Table xxxxxxxxxxxxx:xxxx.xxxx." .So how can i append values to a bigquery table for some specific columns through API calls?
Upvotes: 1
Views: 2502
Reputation: 26617
You can append to a table using a narrower schema. That is, if your table has fields 'A', 'B', and 'C', you can append a CSV file that has only fields 'A', and 'C', as long as field 'B' is marked as Optional (which is the default). Just make sure you provide the correct schema of your CSV file with the load job.
Alternately, the 'allowJaggedRows' option may help you here. This lets you specify fewer columns than are in your schema, and the remainder will be padded with nulls. Of course, of you want to skip columns in the middle of the schema, you may be out-of-luck.
Finally, you can update the schema to add columns via the tables.update() or tables.patch() call. This can let you add columns that weren't in the original table.
Upvotes: 1
Reputation: 517
Using the JSON data format instead of CSV you can do so, provided that your fields are marked as NULLABLE (and not REQUIRED).
This part of the documentation introduces the JSON format: https://developers.google.com/bigquery/preparing-data-for-bigquery
Upvotes: 0