谷歌应用程序脚本电子表格和Bigquery查询

时间:2018-10-04 17:37:55

标签: google-apps-script google-bigquery

下面的示例来自

https://github.com/gsuitedevs/apps-script-samples/blob/master/advanced/bigquery.gs#L26-L28

我试图在bigquery中运行查询,但是我正在 “无效的表名:lui [尝试使用标准SQL(https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)]。(第68行,文件“ bigquery””)

要使它正常工作,我需要做什么?

1 个答案:

答案 0 :(得分:3)

如果要运行以下查询:

SELECT TOP(word, 300) AS word, COUNT(*) AS word_count ' +
      'FROM publicdata:samples.shakespeare WHERE LENGTH(word) > 10;'

在旧版方言中提供的BigQuery控制台中,请确保已启用以下选项:在Options中使用旧版SQL

或者您可以migrate query from LEGACY to STANDARD SQL

 SELECT APPROX_TOP_COUNT(word, 300) AS word, COUNT(*) AS word_count 
    FROM `publicdata.samples.shakespeare` WHERE LENGTH(word) > 10;

此外,如果您要从Google App脚本运行标准SQL查询,请添加标记useLegacySql,如下所示:

var job = {
configuration: {
  query: {
    query: 'SELECT APPROX_TOP_COUNT(word, 300) AS word, COUNT(*) AS word_count +
        FROM `publicdata.samples.shakespeare` WHERE LENGTH(word) > 10;',
    useLegacySql: false
    }