简体   繁体   中英

How to delete a column inside a nested column in Big Query

I tried doing this query:

create or replace table `project.dataset.new_table` as 
    select * replace(
      array(select as struct * except(address2) from t.addresses) 
      as addresses)
    from `project.dataset.table` t
 

based on this question: How to delete a column in BigQuery that is part of a nested column

But I get this error: "Values referenced in FROM clause must be arrays. t.addresses has type STRUCT<... "

The schema of my nested column is table is:

[
 {
    "fields": [
      {
        "name": "IsHappy",
        "type": "BOOLEAN"
      },
      {
        "fields": [
          {
            "name": "Description",
            "type": "STRING"
          }
        ],
        "mode": "REPEATED",
        "name": "FuncTypes",
        "type": "RECORD"
      },

      {
        "name": "address2",   --->hoping to delete this
        "type": "INTEGER"
      },
  
    ],
    "name": "addresses",
    "type": "RECORD"
  }
]

May I ask what I should change or what the error means?

Use below

create or replace table your_new_table as 
select * replace(
      (select as struct addresses.* except(address2)) 
      as addresses
  )
from your_table;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM