为了解决这个问题,你需要使用标准日期格式(例如'YYYY-MM-DD')将日期值包含在查询字符串中。 或者,你可以将日期转换为UNIX时间戳(以秒为单位)并将其作为整数输入。
以下是使用Python的示例代码:
from google.cloud import bigquery
import datetime
client = bigquery.Client()
# Using standard date format
query_string = """
SELECT *
FROM your_table
WHERE date_column = '2021-05-01'
"""
# Using UNIX timestamp
date_to_check = datetime.datetime(2021, 5, 1)
timestamp = int(date_to_check.timestamp())
query_string = f"""
SELECT *
FROM your_table
WHERE date_column = TIMESTAMP_SECONDS({timestamp})
"""
query_job = client.query(query_string)
results = query_job.result()
请注意,上述示例假定你已经正确设置了BigQuery客户端的身份验证凭据。