Database Reference
In-Depth Information
If a table doesn't have a schema, you always can add one. If a table already
has a schema, you can't remove fields, and the only change you can make
to a field is to change the mode from REQUIRED to NULLABLE . You can,
however add fields, but again with restrictions. The fields you add must
have the mode set to NULLABLE or REPEATED (or empty because NULLABLE
is the default). This restriction makes sense because if you added a new
required field, all previous data in the table wouldn't have had that field, so
it wouldn't match the schema. You can also only add fields at the end of the
schema.
Following is an example of a curl request adding a field to the table
schema:
$ SCHEMA2="{'fields': [ \
{'name':'foo', 'type': 'STRING'}, \
{'name': 'bar', 'type': 'FLOAT'}]}"
$ TABLE_JSON="{'tableReference': ${TABLE_REF},
'schema': ${SCHEMA2}}"
$ curl -H "$(python auth.py)" \
- H "Content-Type: application/json" \
- X PUT \
-- data-binary "${TABLE_JSON}" \
"${TABLES_URL}/table1"
{
"tableReference": {
"projectId": "bigquery-e2e",
"datasetId": "scratch",
"tableId": "table1"
},
"schema": {
"fields": [
{
"name": "foo",
"type": "STRING"
},
{
"name": "bar",
Search WWH ::




Custom Search