dimitri / pgloader

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

Floating point Infinity values in SQLite generate errors loading into Postgres #1341

Open zaneselvans opened 2 years ago

zaneselvans commented 2 years ago
2021-11-28T19:50:59.013000Z LOG pgloader version "3.6.2"
2021-11-28T19:50:59.045000Z LOG Migrating from #<SQLITE-CONNECTION sqlite:///home/zane/code/catalyst/pudl-work/sqlite/pudl.sqlite {10053F2243}>
2021-11-28T19:50:59.045000Z LOG Migrating into #<PGSQL-CONNECTION pgsql://zane@UNIX:5434/pudl {100554BA43}>
2021-11-28T19:51:07.282000Z ERROR Database error 22P02: invalid input syntax for type double precision: "#.DOUBLE-FLOAT-POSITIVE-INFINITY"
CONTEXT: COPY generation_fuel_nuclear_eia923, line 23446, column fuel_mmbtu_per_unit: "#.DOUBLE-FLOAT-POSITIVE-INFINITY"
2021-11-28T19:51:47.451000Z ERROR Database error 22P02: invalid input syntax for type double precision: "#.DOUBLE-FLOAT-POSITIVE-INFINITY"
CONTEXT: COPY generation_fuel_eia923, line 2503636, column fuel_mmbtu_per_unit: "#.DOUBLE-FLOAT-POSITIVE-INFINITY"
AndrewNelis commented 1 year ago

I came up against this issue. I don't have time to file a PR yet (though it looks like there hasn't been recent activity on this?) but I can share the code change I made to fix this:

src/utils/transforms.lisp changed:


(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."
  (declare (type (or null fixnum float string) float))
  (when float
    (cond
      ((> float most-positive-double-float) "Infinity")
      ((< float most-negative-double-float) "-Infinity")
      (t (typecase float
                      (double-float (let ((*read-default-float-format* 'double-float))
                                        (princ-to-string float)))
                      (string       float)
                      (t            (princ-to-string float)))))))