日期 2021-01-01 的 PostgreSQL returns 错误 date_part

PostgreSQL returns wrong date_part for week for date 2021-01-01

如果我 运行 以下查询,我会得到非常奇怪的结果。我只从 1 月 4 日星期一开始获得 第 1 周 (如预期)。我在一组查询中使用它来计算每周的 covid 病例,这完全毁了我的一天:/

SELECT date_part('week', '2021-01-01'::date) as week, date_part('year', '2021-01-01'::date) as year;
week year
53   2021

版本:x86_64-pc-linux-musl 上的 PostgreSQL 12.3,由 gcc (Alpine 9.3.0) 9.3.0 编译,64 位

As documented in the manual 'week' uses the ISO definition 第一周。

要获取相应的 (ISO) 年份,请使用 'isoyear'

SELECT date_part('week', '2021-01-01'::date) as week, 
       date_part('isoyear', '2021-01-01'::date) as year;

以上正确returns 53, 2020