mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-09 15:56:58 +02:00
Improve sexp parser and standard symbols support.
Also add split-sequence to the list of special cases that we can use and is not found in the pgloader.transforms package. Fixes #965.
This commit is contained in:
parent
501cbed745
commit
12e788094b
@ -17,11 +17,23 @@
|
|||||||
(defrule sexp-symbol (and (symbol-first-character-p character)
|
(defrule sexp-symbol (and (symbol-first-character-p character)
|
||||||
(* (symbol-character-p character)))
|
(* (symbol-character-p character)))
|
||||||
(:lambda (schars)
|
(:lambda (schars)
|
||||||
(pgloader.transforms:intern-symbol
|
(if (char= #\: (car schars))
|
||||||
(text schars)
|
(read-from-string (text schars))
|
||||||
'(("nil" . cl:nil)
|
(pgloader.transforms:intern-symbol
|
||||||
("precision" . pgloader.transforms::precision)
|
(text schars)
|
||||||
("scale" . pgloader.transforms::scale)))))
|
'(("nil" . cl:nil)
|
||||||
|
("cl:t" . cl:t)
|
||||||
|
("precision" . pgloader.transforms::precision)
|
||||||
|
("scale" . pgloader.transforms::scale)
|
||||||
|
("split-sequence" . split-sequence:split-sequence))))))
|
||||||
|
|
||||||
|
(defrule sexp-char (and #\# #\\
|
||||||
|
(alpha-char-p character)
|
||||||
|
(+ (or (alpha-char-p character)
|
||||||
|
(digit-char-p character)
|
||||||
|
#\_)))
|
||||||
|
(:lambda (char-name)
|
||||||
|
(read-from-string (text char-name))))
|
||||||
|
|
||||||
(defrule sexp-string-char (or (not-doublequote character) (and #\\ #\")))
|
(defrule sexp-string-char (or (not-doublequote character) (and #\\ #\")))
|
||||||
|
|
||||||
@ -40,7 +52,7 @@
|
|||||||
(cons car cdr)))
|
(cons car cdr)))
|
||||||
|
|
||||||
(defrule sexp-atom (and ignore-whitespace
|
(defrule sexp-atom (and ignore-whitespace
|
||||||
(or sexp-string sexp-integer sexp-symbol))
|
(or sexp-char sexp-string sexp-integer sexp-symbol))
|
||||||
(:lambda (atom)
|
(:lambda (atom)
|
||||||
(bind (((_ a) atom)) a)))
|
(bind (((_ a) atom)) a)))
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ REGRESS= allcols.load \
|
|||||||
csv-nulls.load \
|
csv-nulls.load \
|
||||||
csv-temp.load \
|
csv-temp.load \
|
||||||
csv-trim-extra-blanks.load \
|
csv-trim-extra-blanks.load \
|
||||||
|
csv-using-sexp.load \
|
||||||
csv.load \
|
csv.load \
|
||||||
copy.load \
|
copy.load \
|
||||||
copy-hex.load \
|
copy-hex.load \
|
||||||
|
29
test/csv-using-sexp.load
Normal file
29
test/csv-using-sexp.load
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* See https://github.com/dimitri/pgloader/issues/965
|
||||||
|
*/
|
||||||
|
LOAD CSV
|
||||||
|
FROM INLINE(id,f1)
|
||||||
|
INTO postgresql:///pgloader
|
||||||
|
TARGET TABLE sexp
|
||||||
|
(
|
||||||
|
id,
|
||||||
|
f1 text using (format nil "~{~a~^ ~}"
|
||||||
|
(split-sequence #\Space f1 :remove-empty-subseqs cl:t))
|
||||||
|
)
|
||||||
|
|
||||||
|
WITH truncate,
|
||||||
|
fields terminated by ','
|
||||||
|
|
||||||
|
BEFORE LOAD DO
|
||||||
|
$$ drop table if exists sexp; $$,
|
||||||
|
$$ CREATE TABLE sexp
|
||||||
|
(
|
||||||
|
id int,
|
||||||
|
f1 text
|
||||||
|
)
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
1,Hello World
|
||||||
|
2,Hello World
|
||||||
|
2, foobar foobaz
|
3
test/regress/expected/csv-using-sexp.out
Normal file
3
test/regress/expected/csv-using-sexp.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
1 Hello World
|
||||||
|
2 Hello World
|
||||||
|
2 foobar foobaz
|
Loading…
Reference in New Issue
Block a user