snowflake 中的日期函数似乎没有按预期工作

The date functions in snowflake doesn't seem to work as expected

我不明白为什么

SELECT YEAROFWEEK('2017-01-01T00:00:00.000+00:00'::timestamp) returns "2016"

SELECT WEEK('2017-01-01T00:00:00.000+00:00'::timestamp) returns "52"

谁能帮我理解一下?

稍加挖掘,我的答案来自 https://docs.snowflake.net/manuals/sql-reference/parameters.html#week-of-year-policy

这是决定其工作方式的一年中的一周政策的文档 - https://docs.snowflake.net/manuals/sql-reference/parameters.html#week-of-year-policy

举个例子可能会有帮助。 week_of_year_policy 在新创建的帐户上默认设置为 0。


select YEAROFWEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as yow
     , WEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as w;

+------+----+
|  YOW |  W |
+------+----+
| 2016 | 52 |
+------+----+

alter session set week_of_year_policy = 1;

select YEAROFWEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as yow
     , WEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as w;

+------+---+
|  YOW | W |
+------+---+
| 2017 | 1 |
+------+---+