【发布时间】:2016-11-22 22:32:21
【问题描述】:
当我尝试使用 node.js BQ API 运行以下查询时出现 ApiError: Function not found: STRFTIME_UTC_USEC 错误:
SELECT STRFTIME_UTC_USEC(created, "%h %d %Y") as user_created from `tablePath`
根据 BQ 文档 https://cloud.google.com/bigquery/docs/reference/legacy-sql#datetimefunctions ,函数 STRFTIME_UTC_USEC 在 BQ 中可用。事实上,相同的查询在 BQ 控制台网站上的查询生成器中工作(只需将表转义字符从 `` 更改为 [])。
调用查询的代码如下:
const BigQuery = require('@google-cloud/bigquery');
const sqlQuery = SELECT STRFTIME_UTC_USEC(created, "%h %d %Y") as user_created from `tablePath`
const options = {
query: sqlQuery,
useLegacySql: false // Use standard SQL syntax for queries.
};
bigquery.query(options)
.then(function (results) {
const rows = results[0];
console.log(rows);
callback(rows);
});
有什么解决方案可以使用用于 BigQuery 的 node.js API 格式化时间戳吗?尝试在查询字符串中使用 YEAR() 函数时,我也遇到了同样的错误。
【问题讨论】: