迁移oracle app到postgresql日期/时间字段值超出范围:“1400-02-29 00:00:00 AD”

时间:2017-07-24 13:28:07

标签: oracle postgresql oracle-fdw

我将应用程序从oracle迁移到postgresql。在我已经迁移的其中一个函数中,我将数据从不同的oracle db(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

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

有什么想法吗?

1 个答案:

答案 0 :(得分: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标准是合理的。我不知道这个论点是否有效,但我不会深入挖掘,因为你似乎已经解决了你的问题。