how to change the first day of the week in PostgreSQL

前端 未结 2 1225
闹比i
闹比i 2021-01-25 12:50

I need to change the week start date from Monday to Saturday in PostgreSQL. I have tried SET DATEFIRST 6; but it doesn\'t work in PostgreSQL. Plea

2条回答
  •  日久生厌
    2021-01-25 13:27

    You can just add +x, where x is the offset between postgres dow and what you want to achieve.

    For example:

    You want Sunday to be the first day of the week. 2018-06-03 is a Sunday and you want to extract the dow of it:

    SELECT EXTRACT(DOW FROM DATE '2018-06-03')+1;
    

    returns 1

    That is probably the reason why postgres dow yields 0 for Sunday. Would it be 7, then

    SELECT EXTRACT(DOW FROM DATE '2018-06-03')+1; 
    

    would return 8.

提交回复
热议问题