google-bigquery - 如何在 BigQuery 中使用 dateformat()?

标签 google-bigquery

当我尝试使用 DateFormat 函数格式化日期时,如下所示:

with table1 as (select date(2018,3,08) as d1)
select DateFormat(date(d1), 'yyyy-MM-dd')as d2 from table1;

返回以下错误:

Error: Function not found: DateFormat at [2:8]

我做错了什么?

最佳答案

First - DATE(2018,3,08) 已经是 DATE 数据类型,并将日期返回为 2018-03-08,因此您不需要执行任何额外操作格式化

第二 - 如果出于某种原因仍然需要将其格式化为字符串,例如 MM-DD-YYYY 您可以使用 FORMAT_DATE功能如下例所示

#standardSQL
WITH table1 AS (
  SELECT DATE(2018,3,08) AS d1
)
SELECT d1, FORMAT_DATE('%m-%d-%Y', d1) AS d2
FROM table1    

输出为

Row d1          d2   
1   2018-03-08  03-08-2018   

关于google-bigquery - 如何在 BigQuery 中使用 dateformat()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49172415/

相关文章:

google-bigquery - Google Bigquery 架构推断不正确

python - BigQuery Python 客户端 : Creating a Table from Query with a Table Description

node.js - 用于创建外部表的 BigQuery Node.js api

python - 不使用 Google Cloud Storage 将 BigQuery 数据导出为 CSV

google-bigquery - 如何在 Google BigQuery 中创建临时表

python - 在 Tensorflow 中使用 BigQueryReader 读取数据

google-analytics - Google Analytics 数据中的命中数序列

google-bigquery - Bigquery如何查询多个相同结构的表?

python-3.x - pd.to_gbq() 从 pandas 加载到 bigquery() 是否有限制?

google-bigquery - BigQuery Google 时区转换