BigQuery 脚本:根据表列中包含的每一行运行 SQL 查询

问题描述

我的源表包括url_idsql[标准sql,字符串]

enter image description here

我想运行字符串列“sql”中的每个 sql 语句,并将结果与​​对应的 url_id 连接起来

预期结果

enter image description here

更新

为了便于重现,我从公共 BQ 导入了一个类似的模式:

bigquery-public-data.covid19_italy.data_by_province

enter image description here

如果我跑

select string_agg(
    format('select %i as url_id,(%s) as simpleSKU',url_id,sql),' union all '   )

FROM `xxx.staging.test_query

它返回

enter image description here

解决方法

考虑以下

execute immediate (
  select 'select url_id,region_name from (' || string_agg(
    format('select %i as url_id,array(%s) as region_names',url_id,sql),' union all '
  ) || '),unnest(region_names) as region_name'
  from your_table
);   

如果应用于您问题中的样本数据 - 输出它

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...