I am struggling to update a table in Google BigQuery using the BigRQuery package in R. I have only managed to patch the new column names but not to update the values.
Here is my code so far:
library(bigrquery)
library(tidyverse)
projectId = "ABCD"
datasetId = "test"
tableId = 'table1'
mydf = mpg #just loading an example dataset
x <- list(projectId = projectId,
datasetId = datasetId,
tableId = tableId)
upload a table for the first time
bq_table_upload(x, values = mydf, fields = as_bq_fields(mydf))
now add a column to mydf
mydf$new_column = 0
and try to upload it
bq_table_upload(x, values = mydf, fields = as_bq_fields(mydf))
this gives an error that the table already exists.
I can add a new column using
bq_table_patch(x, fields = as_bq_fields(mydf))
But it is created with "Null" values everywhere, I do not understand how to upload the values (in this case they should be 0) in "new_column"
Any help would be greatly appreciated!