Google BigQuery:如果project_id包含连字符“ - ”,则使用TABLE_QUERY。 [英] Google BigQuery: Using TABLE_QUERY if project_id contains a hyphen "-"

查看:137
本文介绍了Google BigQuery:如果project_id包含连字符“ - ”,则使用TABLE_QUERY。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这延伸了Jordan的帖子:
如何在BigQuery中使用TABLE_QUERY()函数?



以下是一个工作TABLE_QUERY SQL的示例。

  SELECT count(*)
FROM TABLE_QUERY(publicdata:samples,
MSEC_TO_TIMESTAMP(creation_time)< DATE_ADD(CURRENT_TIMESTAMP(),-7 ,'DAY'))

但是,如果project_id包含一个 - 连字符,TABLE_QUERY将失败。例如:

 选择任何
FROM TABLE_QUERY(other-public-data:samples,
MSEC_TO_TIMESTAMP (creation_time)< DATE_ADD(CURRENT_TIMESTAMP(),-7,'DAY'))

可能因为解释器会看到一个减法操作。

没有eval(JavaScript)或exec(Python)操作将字符串转换为变量名称,有没有任何建议如何在BigQuery中实现这一功能?

解决方案

Escapewith []:

 选择任何
FROM TABLE_QUERY([other-public-data:samples],
MSEC_TO_TIMESTAMP(creation_time)< DATE_ADD(CURRENT_TIMESTAMP() 7,'DAY'))


This extends Jordan's post here: How do I use the TABLE_QUERY() function in BigQuery?

Here is an example of working TABLE_QUERY SQL.

SELECT count(*)
FROM TABLE_QUERY(publicdata:samples,
    "MSEC_TO_TIMESTAMP(creation_time) < DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY')")

However, TABLE_QUERY fails if the project_id contains a "-" hyphen. For example:

SELECT whatever
FROM TABLE_QUERY(other-public-data:samples,
    "MSEC_TO_TIMESTAMP(creation_time) < DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY')") 

Likely because the interpreter sees a subtraction operation.

Without an "eval" (JavaScript) or "exec" (Python) operation to convert strings to variable names, are there any suggestions to get this working in BigQuery?

解决方案

"Escape" with []:

SELECT whatever
FROM TABLE_QUERY([other-public-data:samples],
  "MSEC_TO_TIMESTAMP(creation_time) < DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY')")

这篇关于Google BigQuery:如果project_id包含连字符“ - ”,则使用TABLE_QUERY。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆