From a9afddf8ed83b42f81a30e7f45389daeb060555d Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sat, 21 Oct 2017 21:03:58 +0200 Subject: [PATCH] Accept quoted namestrings as target type names for cast rules. This allows passing "double precision" rather than float8, for example. Fix #650. --- src/parsers/command-cast-rules.lisp | 7 ++++--- test/mysql/my.load | 6 +++++- test/mysql/my.sql | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/parsers/command-cast-rules.lisp b/src/parsers/command-cast-rules.lisp index e007f89..9b5ffb0 100644 --- a/src/parsers/command-cast-rules.lisp +++ b/src/parsers/command-cast-rules.lisp @@ -47,9 +47,10 @@ ,@(when d-s-p (list :default default)) ,@(when ai-s-p (list :auto-increment auto-increment)))))) -(defrule cast-type-name (and (alpha-char-p character) - (* (or (alpha-char-p character) - (digit-char-p character)))) +(defrule cast-type-name (or double-quoted-namestring + (and (alpha-char-p character) + (* (or (alpha-char-p character) + (digit-char-p character))))) (:text t)) (defrule cast-to-type (and kw-to cast-type-name ignore-whitespace) diff --git a/test/mysql/my.load b/test/mysql/my.load index 1221175..e9dd010 100644 --- a/test/mysql/my.load +++ b/test/mysql/my.load @@ -13,7 +13,11 @@ load database to text drop not null using empty-string-to-null, column base64.id to uuid drop typemod, - column base64.data to jsonb using base64-decode + column base64.data to jsonb using base64-decode, + + type decimal + when (and (= 18 precision) (= 6 scale)) + to "double precision" drop typemod BEFORE LOAD DO $$ create schema if not exists mysql; $$; diff --git a/test/mysql/my.sql b/test/mysql/my.sql index 4401508..e39de6d 100644 --- a/test/mysql/my.sql +++ b/test/mysql/my.sql @@ -33,6 +33,14 @@ insert into `geom`(`p`, `l`) values (ST_GeomFromText('POINT(1 1)'), ST_GeomFromText('LINESTRING(-87.87342467651445 45.79684462673078,-87.87170806274479 45.802110434248966,-87.84492888794016 45.79732335706963,-87.84046569213925 45.79349339919981,-87.83703246459994 45.795887153715135,-87.82261290893646 45.7954084110377,-87.82261290893646 45.781523084289475,-87.82879271850615 45.7796075953549,-87.84115233764729 45.779128712838755,-87.85110869751074 45.78008647375808,-87.83737578735439 45.782001946240946,-87.84527221069374 45.78343850741725)')); +/* + * https://github.com/dimitri/pgloader/issues/650 + */ +CREATE TABLE propertydecimal ( + ID decimal(18,0) NOT NULL, + propertyvalue decimal(18,6) DEFAULT NULL, + PRIMARY KEY (ID) +); create table `base64` (