Handle camelCase column names for CSV, fix #79 again.

The previous patch didn't take into account the need to retain the case
of the PostgreSQL column names when using double-quotes in the load
command, which is now properly forwarded down in the COPY command.
This commit is contained in:
Dimitri Fontaine 2014-06-16 17:33:14 +02:00
parent 0cba5edacd
commit f5c703c206
3 changed files with 13 additions and 6 deletions

View File

@ -1558,13 +1558,17 @@ load database
(:lambda (options)
(alexandria:alist-plist options)))
(defrule csv-bare-field-name (and (or #\_ (alpha-char-p character))
(defrule csv-raw-field-name (and (or #\_ (alpha-char-p character))
(* (or (alpha-char-p character)
(digit-char-p character)
#\_)))
(:text t))
(defrule csv-quoted-field-name (and #\" csv-bare-field-name #\")
(defrule csv-bare-field-name csv-raw-field-name
(:lambda (name)
(string-downcase name)))
(defrule csv-quoted-field-name (and #\" csv-raw-field-name #\")
(:lambda (csv-field-name)
(destructuring-bind (open name close) csv-field-name
(declare (ignore open close))

View File

@ -134,7 +134,10 @@
;; this function update :rows stats
#'pgloader.pgsql:copy-from-queue dbname table-name queue
;; we only are interested into the column names here
:columns (mapcar #'car (columns csv))
:columns (mapcar (lambda (col)
;; always double quote column names
(format nil "~s" (car col)))
(columns csv))
:truncate truncate)
;; now wait until both the tasks are over

View File

@ -16,8 +16,8 @@
*/
LOAD CSV
FROM inline (x, y, a, b, c, d)
INTO postgresql:///pgloader?csv (a, b, d, c)
FROM inline (x, y, a, b, c, "camelCase")
INTO postgresql:///pgloader?csv (a, b, "camelCase", c)
WITH truncate,
skip header = 1,
@ -35,7 +35,7 @@ LOAD CSV
a bigint,
b bigint,
c char(2),
d text
"camelCase" text
);
$$;