我想使用两个 SQL 脚本使用bq query
命令在 BigQuery 中创建和更新表。这是两个脚本:
1-创建表
EXECUTE IMMEDIATE
'''CREATE TABLE IF NOT EXISTS dataset.newtable (
id STRING, ''' ||
(SELECT STRING_AGG(
segment ||
" INT64 " ORDER BY segment
) FROM (
SELECT DISTINCT segment FROM dataset.source
)
) ||
''')''';
2-更新表格
EXECUTE IMMEDIATE
'''INSERT dataset.newtable (
SELECT id, ''' ||
( SELECT STRING_AGG("COUNTIF(
segment = '" ||
segment ||
"') AS " ||
segment ORDER BY segment
) FROM (
SELECT DISTINCT segment FROM dataset.source
) ) ||
''' FROM dataset.source GROUP BY 1 ORDER BY 1
)''';
使用这两个脚本作为bq query
命令查询时,出现错误:
Syntax error: Expected keyword IMMEDIATE but got to end of the script at [1:8]
有没有其他方法可以做到这一点?
谢谢