mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-08 07:16:58 +02:00
Improve CSV date format, fix #293.
The date format wouldn't allow using colon (:) in the noise parts of it, and would also insist that milliseconds should be on 4 digits and micro seconds on 6 digits. Allow for "ragged" input and take however many digits we actually find in the input.
This commit is contained in:
parent
a195ac6dd4
commit
98f18c4877
@ -35,8 +35,15 @@
|
||||
&allow-other-keys)
|
||||
(loop
|
||||
:for (name start end) :in format
|
||||
:for ragged-end := (when end
|
||||
(cond ((member name '(:msecs :usecs))
|
||||
;; take any number of digits up to
|
||||
;; the specified field lenght
|
||||
;; (less digits are allowed)
|
||||
(min end (length date-string)))
|
||||
(t end)))
|
||||
:when (and start end)
|
||||
:append (list name (subseq date-string start end)))
|
||||
:append (list name (subseq date-string start ragged-end)))
|
||||
(if (or (string= year "0000")
|
||||
(string= month "00")
|
||||
(string= day "00"))
|
||||
@ -91,7 +98,7 @@
|
||||
microseconds
|
||||
noise)))
|
||||
|
||||
(defrule noise (+ (or #\- #\. #\Space #\* #\# #\@ #\/ #\\ "T"))
|
||||
(defrule noise (+ (or #\: #\- #\. #\Space #\* #\# #\@ #\/ #\\ "T"))
|
||||
(:lambda (x) (incf *offset* (length (text x))) nil))
|
||||
|
||||
(defrule year (or year4 year3 year2))
|
||||
|
@ -3,7 +3,7 @@ LOAD CSV
|
||||
(
|
||||
"row num",
|
||||
ts [date format 'YYYY-MM-DD HH24-MI-SS.US'],
|
||||
hr [date format 'HH24.MI.SS']
|
||||
hr [date format 'HH24:MI.SS']
|
||||
)
|
||||
INTO postgresql:///pgloader?dateformat ("row num", ts, hr)
|
||||
|
||||
@ -25,6 +25,6 @@ LOAD CSV
|
||||
);
|
||||
$$;
|
||||
|
||||
1,1999-10-02 00-33-12.123456,"00.05.02"
|
||||
2,2014-10-02 00-33-13.123456,"18.25.52"
|
||||
3,2014-10-02 00-33-14.123456,13.14.15
|
||||
1,1999-10-02 00-33-12.123456,"00:05.02"
|
||||
2,2014-10-02 00-33-13.123,"18:25.52"
|
||||
3,2014-10-02 00-33-14.1234,13:14.15
|
||||
|
Loading…
Reference in New Issue
Block a user