Reputation: 8247
I have a dataframe which I have earlier uploaded to the GCP BQ table, but later on there was some mistake in the existing dataframe's column names and I changed the column names. I am doing the following in R to truncate the existing table and upload the new dataframe with changed column names.
price_indices <- bq_table_create(x = stock_index_table,
fields = as_bq_fields(df),
overwrite = TRUE,
friendly_name = "Price Indexes",
description = "Price indexes for TCS stock"
)
bq_table_upload(x = stock_index_table, values = df,
create_disposition='CREATE_IF_NEEDED', write_disposition='WRITE_TRUNCATE')
When I run bq_table_create
it gives me an error saying, table already exists. When I run bq_table_upload
it gives me an error saying Error while reading data, error message: JSON parsing error in row starting at position 0: No such field
Any help is appreciated.
Upvotes: 0
Views: 653
Reputation: 605
Set the create_disposition parameter to "CREATE_NEVER" to avoid creating a new table, and set the write_disposition parameter to "WRITE_TRUNCATE" to overwrite the existing table.
bq_table_upload(x = stock_index_table, values = df,
create_disposition='CREATE_NEVER', write_disposition='WRITE_TRUNCATE')
Upvotes: 0