从星期几中提取实际日期

Extracting real dates from dates of the week

我知道如何从日期中提取 DOW。例如 SELECT EXTRACT(DOW FROM '2018-04-23'::date)

但是我怎样才能反过来呢?我如何获取一系列 DOW 并将它们转换为给定一周的下一个日期? (相对于本周)。

+-----+---------+
| id  | the_dow |
+-----+----------
| 358 | 1       |
| 359 | 2       |
| 360 | 5       |
| 361 | 2       |
| 362 | 3       |
+-----+---------+

只需将该数字添加到一周的开始:

date_trunc('week', current_date)::date + the_dow

据我所知date_trunc()使用ISO定义的星期,所以第一天是星期一。使用 isodow 进行提取并从该值中减去 1 会更容易。