dimitri / pgloader

Migrate to PostgreSQL in a single command!
http://pgloader.io
Other
5.47k stars 550 forks source link

MariaDB (10.3.34) to Postgresql (14.4) #1438

Closed NetzaWhoop closed 2 years ago

NetzaWhoop commented 2 years ago

Tried to migrate MariaDB (from docker container) to postgresql (another container), both in a compose file. The problem is with tables that have the types curdate() or CURRENT_TIMESTAMP in MariaDB. I installed pgloader with the command apt-get install. Everything seems fine in both databases, only that step. Here the structuree of my compose file:

version: '3.8'
services:
  postgres-db:
    image: postgres:14.4
  maria-db:
    image: mariadb:10.3.34

I get the following error when running my .load file:

2022-09-26T15:37:33.905000Z ERROR Database error 22007: invalid input syntax for type date: "curdate()"
QUERY: CREATE TABLE trace.report 
(
  id          bigserial not null,
  station varchar(100) default NULL,
         ...................................
  datedata    date default 'curdate()',
  datetime    timestamp default CURRENT_TIMESTAMP

I can exclude the tables and the migration works fine, but I'd like to do a cast to migrate the entire database, so I can do that in other databases I have to migrate.

Found a lot about the year zero in MySQL, but nothing on casting curdate().

This is my .load file:
LOAD DATABASE
     FROM      mysql://user:pass@host.docker.internal/trace
     INTO pgsql://postgres:pass@localhost/trace

 CAST column report.datedata to date,
      column report.datetime to timestamp,
      column report.datedata to date,
      column report.datetime to timestamp
;

Maybe I'm missing something very simple, hope you can help me. Thanks!

NetzaWhoop commented 2 years ago

I solved it using this line, replacing from the documentation:

CAST type date when default "0000-00-00" to date drop default
         using zero-dates-to-null

Ignored the zero dates to null cause I didn't have null values, and it resulted in a line like this:

 CAST type date when default "curdate()" to date drop default

And after checking in depth the Default MySQL Casting Rules in the documentation for version v3.6.2: https://pgloader.readthedocs.io/en/v3.6.2/ref/mysql.html

Still checking if migration was correctly executed, but I think specifically the "curdate()" type migration isn't that intuitive, it could be better explained, but pgloader works great though.