将时间戳从MySQL导入Postgres

时间:2015-09-22 23:04:47

标签: mysql postgresql datetime import

我使用mysqldumppsql从MySQL迁移到Postgres并收到此错误:

  

错误:日期/时间字段值超出范围:" 0000-00-00 00:00:00"在角色52   声明:插入" cron"价值观(1,' 2015-07-11 05:21:40',' 0000-00-00 00:00:00',2,58,' updateBid&# 39;,' plus',NULL,NULL),(2,' 2015-07-11 05:21:40',' 0000-00-00

MySQL表看起来像

CREATE TABLE "cron" (
  "id" int(11) NOT NULL,
  "execute_after" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "executed_at" timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',

Postgres表格如下:

CREATE TABLE "cron" (
  "id" int NOT NULL,
  "execute_after" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "executed_at" timestamp,

如何自动导入此字段?

1 个答案:

答案 0 :(得分:1)

好的我用sed解决了它:

  

mysqldump --compress --compatible postgresql --no-create-info --compact dbname | sed $'s / \'0000-00-0000,00:00:00 /'/ NULL / g'| psql dbname