问题描述
我的源表包括url_id和sql[标准sql,字符串]
我想运行字符串列“sql”中的每个 sql 语句,并将结果与对应的 url_id 连接起来
预期结果
更新
为了便于重现,我从公共 BQ 导入了一个类似的模式:
bigquery-public-data.covid19_italy.data_by_province
如果我跑
select string_agg(
format('select %i as url_id,(%s) as simpleSKU',url_id,sql),' union all ' )
FROM `xxx.staging.test_query
它返回
解决方法
考虑以下
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
);
如果应用于您问题中的样本数据 - 输出它