From c3986b09975b8de42b56aec882a9869aff1fb0a4 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 17 Jul 2015 12:05:28 +0200 Subject: [PATCH] Cast MySQL bigint(20) into numeric, fix #253. In MySQL it's possible to have a bigint of 20 digits when using the "unsigned" variant of the data type, whereas in PostgreSQL there's no such variant and bigints are "limited" to the range -9223372036854775808 to +9223372036854775807 (19 digits numbers). Fix the default casting rule to switch to PostgreSQL numeric in such cases. --- src/sources/mysql/mysql-cast-rules.lisp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sources/mysql/mysql-cast-rules.lisp b/src/sources/mysql/mysql-cast-rules.lisp index 739ceff..1c552dc 100644 --- a/src/sources/mysql/mysql-cast-rules.lisp +++ b/src/sources/mysql/mysql-cast-rules.lisp @@ -69,6 +69,11 @@ :target (:type "boolean" :drop-typemod t) :using pgloader.transforms::bits-to-boolean) + ;; bigint(20) unsigned (or not, actually) does not fit into PostgreSQL + ;; bigint (-9223372036854775808 to +9223372036854775807): + (:source (:type "bigint" :typemod (< 19 precision)) + :target (:type "numeric" :drop-typemod t)) + ;; we need the following to benefit from :drop-typemod (:source (:type "tinyint") :target (:type "smallint" :drop-typemod t)) (:source (:type "smallint") :target (:type "smallint" :drop-typemod t))