diff --git a/.changelog/12626.txt b/.changelog/12626.txt new file mode 100644 index 00000000000..f87f1361ec7 --- /dev/null +++ b/.changelog/12626.txt @@ -0,0 +1,3 @@ +```release-note:bug +bigquery: fixed DROP COLUMN error with bigquery flexible column names in `google_bigquery_table` +``` \ No newline at end of file diff --git a/google/services/bigquery/resource_bigquery_table.go b/google/services/bigquery/resource_bigquery_table.go index 91348be74cf..62ec8539e98 100644 --- a/google/services/bigquery/resource_bigquery_table.go +++ b/google/services/bigquery/resource_bigquery_table.go @@ -1982,7 +1982,11 @@ func resourceBigQueryTableColumnDrop(config *transport_tpg.Config, userAgent str } if len(droppedColumns) > 0 { - droppedColumnsString := strings.Join(droppedColumns, ", DROP COLUMN ") + backquotedDroppedColumns := []string{} + for _, column := range droppedColumns { + backquotedDroppedColumns = append(backquotedDroppedColumns, fmt.Sprintf("`%s`", column)) + } + droppedColumnsString := strings.Join(backquotedDroppedColumns, ", DROP COLUMN ") dropColumnsDDL := fmt.Sprintf("ALTER TABLE `%s.%s.%s` DROP COLUMN %s", tableReference.project, tableReference.datasetID, tableReference.tableID, droppedColumnsString) log.Printf("[INFO] Dropping columns in-place: %s", dropColumnsDDL) diff --git a/google/services/bigquery/resource_bigquery_table_test.go b/google/services/bigquery/resource_bigquery_table_test.go index 6a5fdc17e95..89a35ae192c 100644 --- a/google/services/bigquery/resource_bigquery_table_test.go +++ b/google/services/bigquery/resource_bigquery_table_test.go @@ -415,9 +415,9 @@ func testAccBigLakeManagedTable(bucketName, connectionID, datasetID, tableID, sc file_format = "PARQUET" table_format = "ICEBERG" } - + schema = jsonencode(%s) - + depends_on = [ google_project_iam_member.test ] @@ -2162,6 +2162,14 @@ resource "google_bigquery_table" "test" { { "name": "some_int", "type": "INTEGER" + }, + { + "name": "reserved_word_for", + "type": "STRING" + }, + { + "name": "flexible-column-name-dash", + "type": "STRING" } ] EOH @@ -3070,7 +3078,7 @@ resource "google_bigquery_table" "test" { # Depends on Iceberg Table Files depends_on = [ google_storage_bucket_object.empty_data_folder, - google_storage_bucket_object.metadata, + google_storage_bucket_object.metadata, ] } `, datasetID, bucketName, tableID) @@ -3098,7 +3106,7 @@ resource "google_storage_bucket_object" "datafile" { # Upload Metadata file resource "google_storage_bucket_object" "manifest" { - name = "%s" + name = "%s" content = "gs://${google_storage_bucket.test.name}/${google_storage_bucket_object.datafile.name}" bucket = google_storage_bucket.test.name }