【问题标题】:migration oracle app to postgresql date/time field value out of range: "1400-02-29 00:00:00 AD"将 oracle 应用程序迁移到 postgresql 日期/时间字段值超出范围:“1400-02-29 00:00:00 AD”
【发布时间】:2017-07-24 13:28:07
【问题描述】:

我正在将应用程序从 oracle 迁移到 postgresql。在我已经迁移的一个函数中,我将数据从不同的 oracle 数据库(oracle 中的 db 链接,postgresql 中的 oracle_fdw 扩展)从几个表复制到我的 postgresql db 中的本地表中。但是,我收到下一个错误:

 NOTICE:  Insert data into table from remote table : insert into IP_MAN 
 select * from IP_MAN_production
 NOTICE:     PROCEDURE copy_table : V_Step = 4 // **SQLERRM = date/time field 
 value out of range: "1400-02-29 00:00:00 AD"**
 CONTEXT:  converting column "birthday" for foreign table scan of "ip_man_production", 
 row 32481

当我尝试选择 oracle db 中的特定行时,我得到下一个值:

select date from bezeq.ip_manuim where 
birthday=to_date('29/02/1400','dd/mm/yyyy');

  birthday
  --------
 01010001

生日是数据类型是没有时区的时间戳。

有什么想法吗?

【问题讨论】:

  • 偶然生日是不是只用月份和日期记录的,而不是用年份记录的?如果是这种情况,UPDATE 查询将他们的年份设置为 2000 可以解决您的问题,前提是月份和日期都很重要。
  • 此列中的大多数值都采用 dd/mm/yyyyy 格式,但正如您所见,我提到了选择表格时得到的输出。
  • 你给了我们date字段输出,但birthdate是有问题的。
  • 不不,我写了日期,但我弄错了——那天是生日
  • 嗨,我更新了值并解决了我的问题。谢谢!

标签: oracle postgresql oracle-fdw


【解决方案1】:

PostgreSQL 认为 1400 年不是闰年。

src/include/utils/datetime.h中查看此定义:

/*
 * These are the rules for the Gregorian calendar, which was adopted in 1582.
 * However, we use this calculation for all prior years as well because the
 * SQL standard specifies use of the Gregorian calendar.  This prevents the
 * date 1500-02-29 from being stored, even though it is valid in the Julian
 * calendar.
 */
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))

正如评论所说,拒绝1400-02-29 在技术上是错误的,但模糊地提及 SQL 标准是合理的。我不知道这个论点是否有效,但我不会深入挖掘,因为看起来你已经解决了你的问题。

【讨论】:

  • 确实,我解决了我的问题。所以从技术上讲,我不能将 1582 之前的任何日期插入到 postgresql 表中?
  • 您绝对可以插入到公元前 4713 年的日期,但 PostgreSQL 将根据公历处理闰年,尽管在 1582 年之前有效的儒略历中,每四年是一个闰年(即导致季节向前移动)。但是,所有这一切,虽然对于任何喜欢受虐狂的人来说都是令人兴奋的,但对你的用例来说可能并不重要。
猜你喜欢
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-25
  • 1970-01-01
  • 2015-01-10
  • 2014-02-19
  • 2019-09-27
  • 2016-06-04
相关资源
最近更新 更多