From b78bb6dd31997f3816f35699a151870af6d70806 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 1 Sep 2015 14:32:50 +0200 Subject: [PATCH] Allow quoted field names to contain spaces, fix #285. Given a fully quoted field name, there should be no restriction about using spaces in between the quotes, but the parser used to choke on that case. --- src/parsers/command-csv.lisp | 14 ++++++++++---- test/csv-parse-date.load | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/parsers/command-csv.lisp b/src/parsers/command-csv.lisp index e7046bd..fe27474 100644 --- a/src/parsers/command-csv.lisp +++ b/src/parsers/command-csv.lisp @@ -197,16 +197,22 @@ (defrule csv-field-options (? csv-field-option-list)) (defrule csv-raw-field-name (and (or #\_ (alpha-char-p character)) + (* (or (alpha-char-p character) + (digit-char-p character) + #\Space + #\. + #\$ + #\_))) + (:text t)) + +(defrule csv-bare-field-name (and (or #\_ (alpha-char-p character)) (* (or (alpha-char-p character) (digit-char-p character) #\. #\$ #\_))) - (:text t)) - -(defrule csv-bare-field-name csv-raw-field-name (:lambda (name) - (string-downcase name))) + (string-downcase (text name)))) (defrule csv-quoted-field-name (and #\" csv-raw-field-name #\") (:lambda (csv-field-name) diff --git a/test/csv-parse-date.load b/test/csv-parse-date.load index 72184e5..bde10ca 100644 --- a/test/csv-parse-date.load +++ b/test/csv-parse-date.load @@ -1,6 +1,6 @@ LOAD CSV - FROM inline (rownum, ts [date format 'YYYY-MM-DD HH24-MI-SS.US']) - INTO postgresql:///pgloader?dateformat (rownum, ts) + FROM inline ("row num", ts [date format 'YYYY-MM-DD HH24-MI-SS.US']) + INTO postgresql:///pgloader?dateformat ("row num", ts) WITH truncate, fields optionally enclosed by '"', @@ -14,8 +14,8 @@ LOAD CSV BEFORE LOAD DO $$ drop table if exists dateformat; $$, $$ create table dateformat ( - rownum smallint, - ts timestamp + "row num" smallint, + ts timestamp ); $$;