mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-04 10:31:02 +02:00
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:
parent
0cba5edacd
commit
f5c703c206
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
);
|
||||
$$;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user