我想使用table_query()查询这些表。如何查询日期范围为2017-03-22至2017-03-24的所有表格
我的BQ表的格式是(auctions_other_YYYYMMDDHHM)
BQ表如下:
1.auctions_other_20170322104
2.auctions_other_20170322105
3.auctions_other_20170323206
4.auctions_other_20170323207
5.auctions_other_20170324108
6.auctions_other_20170324209
我正在使用查询:
SELECT * FROM
TABLE_QUERY(chocolate_raw, "table_id contains 'auctions_others_' and
table_id contains '20170322104' and table_id contains '20170324209'
")
WHERE
id='f3667fd6-8329-4124-a4a2-737e637a5e7d'
获取错误:
带有表通配符的FROM子句不匹配表
答案 0 :(得分:2)
首先使用标准SQL(它更简单/更整洁)。因为你有时间和分钟后缀,这使它有点棘手,但这样的东西应该工作:
#standardSQL
SELECT
*
FROM
`<dataset>.auctions_other_*`
WHERE
_TABLE_SUFFIX LIKE '20170322%'
OR _TABLE_SUFFIX LIKE '20170323%'
OR _TABLE_SUFFIX LIKE '20170324%'
答案 1 :(得分:1)
你应该明确考虑使用BigQuery Standard SQL作为Graham建议
如果出于某种原因,您仍然需要使用BigQuery Legacy SQL - 请尝试以下
#legacySQL
SELECT *
FROM TABLE_QUERY(chocolate_raw,
"table_id CONTAINS 'auctions_others_'
AND SUBSTR(table_id, 1 + LENGTH('auctions_others_'), 8)
BETWEEN '20170322' AND '20170324'")
WHERE id='f3667fd6-8329-4124-a4a2-737e637a5e7d'
BigQuery Standard SQL中的类似版本如下所示
#standardSQL
SELECT *
FROM `chocolate_raw.auctions_others_*`
WHERE SUBSTR(_TABLE_SUFFIX, 1, 8) BETWEEN '20170322' AND '20170324'
AND id='f3667fd6-8329-4124-a4a2-737e637a5e7d'