【问题标题】:Compare a character varying with a timestamp比较随时间戳变化的字符
【发布时间】:2019-01-18 22:05:39
【问题描述】:

我正在尝试比较一个在 postgresSQL 中随时间戳变化的字符。

我想获取当前时间之前的所有值与字符变化时间戳相比。

这样比较正确吗?

WHERE to_timestamp('2018-12-25T06:00:00+01:00', 'YYYY-MM-DD HH24:MI:SS') < now()

【问题讨论】:

    标签: sql postgresql timestamp to-timestamp


    【解决方案1】:

    不完全是。文字中有应该解析的时区值。比较:

    select
        to_timestamp('2018-12-25T06:00:00+01:00', 'YYYY-MM-DD HH24:MI:SS') as "seems ok",
        to_timestamp('2018-12-25T07:00:00+02:00', 'YYYY-MM-DD HH24:MI:SS') as "but this is wrong!",
        to_timestamp('2018-12-25T06:00:00+01:00', 'YYYY-MM-DD HH24:MI:SS+TZH:TZM') as "ok",
        to_timestamp('2018-12-25T07:00:00+02:00', 'YYYY-MM-DD HH24:MI:SS+TZH:TZM') as "ok too"
    
            seems ok        |   but this is wrong!   |           ok           |         ok too         
    ------------------------+------------------------+------------------------+------------------------
     2018-12-25 06:00:00+01 | 2018-12-25 07:00:00+01 | 2018-12-25 06:00:00+01 | 2018-12-25 06:00:00+01
    (1 row)
    

    【讨论】:

      猜你喜欢
      • 2012-12-20
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多