BigQuery nested fields: column units of type ARRAY cannot be used in SELECT DISTINCT

我只是一个虾纸丫 提交于 2020-01-25 12:54:07

问题


I want to select unique rows of a table in BigQuery but I get the following error: "Column units of type ARRAY cannot be used in SELECT DISTINCT".

My query is

SELECT DISTINCT * from <table>

Table schema

  {
    "mode": "NULLABLE",
    "name": "company_name",
    "type": "STRING"
  },
  {
    "mode": "NULLABLE",
    "name": "vat_number",
    "type": "STRING"
  },
  {
    "fields": [
      {
        "mode": "NULLABLE",
        "name": "name",
        "type": "STRING"
      }
    ],
    "mode": "REPEATED",
    "name": "industry",
    "type": "RECORD"
  }

How can I select distinct rows of a table with nested fields in BigQuery?


回答1:


You can use the ANY_VALUE function to select the nested field values in a GROUP BY (assuming this value is the same for the entire group):

SELECT
  company_name,
  vat_number,
  ANY_VALUE(industry) AS industry
FROM
  <table>
GROUP BY
  company_name,
  vat_number


来源:https://stackoverflow.com/questions/54441479/bigquery-nested-fields-column-units-of-type-array-cannot-be-used-in-select-dist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!