[英]BigQuery Partition Date | Specific Day | PARSE_DATE
yyyymm is a column in tbl table which is in string format and looks like 202212
which means Dec 2022
yyyymm 是 tbl 表中的一列,采用字符串格式,看起来像202212
,表示Dec 2022
When I am using below query, its creating a new column in the tbl_new
table by the name sample_date
with output as 2022-12-01
.当我使用以下查询时,它会在tbl_new
表中创建一个名为sample_date
的新列,其中 output 为2022-12-01
。
As you can see i am getting 01
date added which i need it to be 15
.如您所见,我正在添加01
日期,我需要它是15
。 Is there any way, to customize date on my own?有什么办法可以自己自定义日期吗?
I tried adding %Y%m15
but its not supporting and giving invalid literal
error in BigQuery.我尝试添加%Y%m15
但它不支持并在 BigQuery 中给出invalid literal
错误。
Current output: 2022-12-01
当前 output: 2022-12-01
Expected Output: 2022-12-15
预计 Output: 2022-12-15
CREATE or replace TABLE
project_id.dataset_id.tbl_new
PARTITION BY
sample_date AS
SELECT
*,
PARSE_DATE('%Y%m',yyyymm) AS sample_date
FROM
project_id.dataset_id.tbl
Using DATE_ADD function, I was able to attain the required result.使用 DATE_ADD function,我能够获得所需的结果。 By default, PARSE_DATE gives 01
as date and using INTERVAL
clause, I was able to achieve the desired output.默认情况下,PARSE_DATE 将01
作为日期并使用INTERVAL
子句,我能够实现所需的 output。
CREATE or replace TABLE
project_id.dataset_id.tbl_new
PARTITION BY
sample_date AS
SELECT
*,
***DATE_ADD(PARSE_DATE('%Y%m',yyyymm), INTERVAL 14 DAY) as sample_date***
FROM
project_id.dataset_id.tbl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.