如何将 'current' mysql 时间戳值迁移到 postgreSQL

How to migrate 'current' mysql timestamp value to postgreSQL

我有 Mysql 数据库包含 table 'tariff' 字段

start_date DATETIME DEFAULT (current_timestamp() + interval 10 year),

当我尝试使用 pgloader 将数据库迁移到 postgreSQL 时出现错误

错误数据库错误 0A000:不再支持日期时间的值“当前” 查询:创建 TABLE yamalkernel.tariff 2021-10-06T09:51:25.248000+03:00 FATAL 创建架构失败,见上文

我运行 pgloader这样

$ pgloader scenario.load

$猫scenario.load

LOAD DATABASE
FROM mysql://user:password@127.0.0.1/database1
INTO postgresql://postgres:postgres@127.0.0.1:5432/database2;

该代码中有几个错误:

  • 使用timestamp代替datetime
  • 使用current_timestamp代替current_timestamp()
  • 区间值需要用单引号括起来

所以你需要使用:

start_date timestamp DEFAULT current_timestamp + interval '10 year'

您可以“告诉”pgLoader 转换“tariff”table(在“CAST”部分中的问题字段(“start_date”) ), 例如如下:

#!/bin/bash

cat <<EOF > file.load
LOAD DATABASE
FROM mysql://user:password@127.0.0.1/database1
INTO postgresql://postgres:postgres@127.0.0.1:5432/database2
CAST column tariff.start_date to "timestamptz DEFAULT now() + interval '10 year'" drop default;
EOF

pgloader -v file.load