首页 > 解决方案 > 如何在 Google BigQuery Composer 和 Cloud Shell 中提交多个查询

问题描述

只是一个简单的问题,请不要告诉我在 Query Composer 和 Google Cloud Shell 中不支持提交多个查询。

当我提交两个语句时(例如,由“;”分隔的 drop table 语句),它告诉我下一行的 drop word 是意外的。

标签: google-bigquery

解决方案


BigQuery 现在支持多语句执行。查看脚本文档。复制示例:

-- Declare a variable to hold names as an array.
DECLARE top_names ARRAY<STRING>;
-- Build an array of the top 100 names from the year 2017.
SET top_names = (
  SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
  FROM `bigquery-public-data`.usa_names.usa_1910_current
  WHERE year = 2017
);
-- Which names appear as words in Shakespeare's plays?
SELECT
  name AS shakespeare_name
FROM UNNEST(top_names) AS name
WHERE name IN (
  SELECT word
  FROM `bigquery-public-data`.samples.shakespeare
);

推荐阅读