postgresql timezone conversion 'EST' != '-05'

前端 未结 2 598
故里飘歌
故里飘歌 2021-01-14 23:24

I am running PostgreSQL 9.6.6 on x86_64-pc-linux-gnu and my time zone is set to \'UTC\'.

Does anyone know why the results of the following SELECT statem

2条回答
  •  感动是毒
    2021-01-14 23:56

    Okay I think I found an answer to my own question:

    According to the PostgreSQL docs, section 9.9.3 at the following link https://www.postgresql.org/docs/9.6/static/functions-datetime.html

    In these expressions, the desired time zone zone can be specified either as a text string (e.g., 'PST') or as an interval (e.g., INTERVAL '-08:00'). In the text case, a time zone name can be specified in any of the ways described in Section 8.5.3.

    So using the INTERVAL syntax, the following appears to work:

    SELECT timezone(INTERVAL '-05:00', '2017-12-21');
          timezone       
    ---------------------
    2017-12-20 19:00:00
    

    I think it is still curious, what exactly SELECT timezone('-05', '2017-12-21'); means, as the following also provides the expected result (with the addition of a TZ offset):

    SELECT timezone('-05', '2017-12-21'::timestamp);
            timezone        
    ------------------------
    2017-12-20 19:00:00+00
    

提交回复
热议问题