Google BigQuery:如果project

编程入门 行业动态 更新时间:2024-10-12 10:26:44
本文介绍了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

本文发布于:2023-11-29 13:43:52,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Google   BigQuery   project

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!