diff --git a/pgloader.1 b/pgloader.1 index 24da748..34b90b4 100644 --- a/pgloader.1 +++ b/pgloader.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "PGLOADER" "1" "February 2016" "ff" "" +.TH "PGLOADER" "1" "March 2016" "ff" "" . .SH "NAME" \fBpgloader\fR \- PostgreSQL data loader @@ -2480,10 +2480,10 @@ When migrating from SQLite the following Casting Rules are provided: Numbers: . .IP "\(bu" 4 -type tinyint to smallint +type tinyint to smallint using integer\-to\-string . .IP "\(bu" 4 -type integer to bigint +type integer to bigint using integer\-to\-string . .IP "\(bu" 4 type float to float using float\-to\-string @@ -2866,6 +2866,24 @@ Out: "(48\.5513589,7\.6926827)" . .IP "" 0 +. +.IP "\(bu" 4 +\fIinteger\-to\-string\fR +. +.IP +Converts a integer string or a Common Lisp integer into a string suitable for a PostgreSQL integer\. Takes care of quoted integers\. +. +.IP "" 4 +. +.nf + +In: "\e"0\e"" +Out: "0" +. +.fi +. +.IP "" 0 + . .IP "\(bu" 4 \fIfloat\-to\-string\fR diff --git a/pgloader.1.md b/pgloader.1.md index 33af8f0..1740087 100644 --- a/pgloader.1.md +++ b/pgloader.1.md @@ -2059,8 +2059,8 @@ When migrating from SQLite the following Casting Rules are provided: Numbers: - - type tinyint to smallint - - type integer to bigint + - type tinyint to smallint using integer-to-string + - type integer to bigint using integer-to-string - type float to float using float-to-string - type real to real using float-to-string @@ -2268,6 +2268,14 @@ The provided transformation functions are: In: "POINT(48.5513589 7.6926827)" Out: "(48.5513589,7.6926827)" + - *integer-to-string* + + Converts a integer string or a Common Lisp integer into a string + suitable for a PostgreSQL integer. Takes care of quoted integers. + + In: "\"0\"" + Out: "0" + - *float-to-string* Converts a Common Lisp float into a string suitable for a PostgreSQL float: diff --git a/src/sources/sqlite/sqlite-cast-rules.lisp b/src/sources/sqlite/sqlite-cast-rules.lisp index 175e034..f775eff 100644 --- a/src/sources/sqlite/sqlite-cast-rules.lisp +++ b/src/sources/sqlite/sqlite-cast-rules.lisp @@ -15,8 +15,11 @@ (:source (:type "nchar") :target (:type "text" :drop-typemod t)) (:source (:type "clob") :target (:type "text" :drop-typemod t)) - (:source (:type "tinyint") :target (:type "smallint")) - (:source (:type "integer") :target (:type "bigint")) + (:source (:type "tinyint") :target (:type "smallint") + :using pgloader.transforms::integer-to-string) + + (:source (:type "integer") :target (:type "bigint") + :using pgloader.transforms::integer-to-string) (:source (:type "float") :target (:type "float") :using pgloader.transforms::float-to-string) diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index 3552fbb..f3ed6f3 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -62,7 +62,8 @@ int-to-ip ip-range convert-mysql-point - float-to-string + integer-to-string + float-to-string empty-string-to-null set-to-enum-array right-trim @@ -186,6 +187,21 @@ (setf (aref point (position #\Space point)) #\,) point))) +(defun integer-to-string (integer-string) + "Transform INTEGER-STRING parameter into a proper string representation of + it. In particular be careful of quoted-integers, thanks to SQLite default + values." + (declare (type (or null string fixnum) integer-string)) + (when integer-string + (typecase integer-string + (integer (princ-to-string integer-string)) + (string (handler-case + (parse-integer integer-string :start 0) + (condition (c) + (declare (ignore c)) + (parse-integer integer-string :start 1 + :end (- (length integer-string) 1)))))))) + (defun float-to-string (float) "Transform a Common Lisp float value into its string representation as accepted by PostgreSQL, that is 100.0 rather than 100.0d0."