【问题标题】:Postgres change year from one year to another yearPostgres 将年份从一年更改为另一年
【发布时间】:2023-02-04 03:45:23
【问题描述】:

我曾尝试在 PostgreSQL 中使用以下内容,但它增加了大约 2000 年。我需要将年份从 2096 年更改为 2001 年或 2000 年并不重要。当我运行它时,它向 2096 年增加了大约 2000 年,使它成为 4096。

UPDATE module_warrants 
  SET receiveddate = receiveddate + MAKE_INTERVAL(YEARS :=2096 -96) 
where receiveddate >= '01-01-2094'

预计年份将从 2096 年减少 96 年至 2000 年。

【问题讨论】:

    标签: postgresql postgresql-14


    【解决方案1】:

    表达式+ MAKE_INTERVAL(YEARS :=2096 -96)添加2000 年 (2096-96) 到当前值。

    但是你想减去号码:

    receiveddate - make_interval(years => 96)
    

    或者

    receiveddate - interval '96 years'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-01
      • 2018-04-05
      • 2012-01-20
      • 2021-08-15
      • 2011-07-09
      • 1970-01-01
      • 2020-08-11
      • 2012-10-16
      相关资源
      最近更新 更多