我使用 mysqldump
和 psql
从 MySQL 迁移到 Postgres 并收到此错误:
ERROR: date/time field value out of range: "0000-00-00 00:00:00" at character 52 STATEMENT: INSERT INTO "cron" VALUES (1,'2015-07-11 05:21:40','0000-00-00 00:00:00',2,58,'updateBid','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,
如何自动导入该字段?
最佳答案
好的,我用 sed
解决了这个问题:
mysqldump --compress --compatible postgresql --no-create-info --compact dbname | sed $'s/\'0000-00-00 00:00:00\'/NULL/g' | psql dbname
关于mysql - 将时间戳从 MySQL 导入到 Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32728434/