mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-11 08:46:59 +02:00
Allow date format parsing to support time.
A useful use case for date parsing at tine input level is to parse time (hour, minutes, seconds) rather than a full date (timestamp). Improve the code so that it's possible to use the date format facility even when the data field lacks the year/month/day information. Fix #288.
This commit is contained in:
parent
bd50ba45ea
commit
04b2779239
@ -42,12 +42,19 @@
|
||||
(string= day "00"))
|
||||
nil
|
||||
(with-output-to-string (s)
|
||||
(format s "~a-~a-~a ~a:~a:~a"
|
||||
(let ((yint (parse-integer year)))
|
||||
;; process 2-digits year formats specially
|
||||
(if (<= (length year) 2) (+ *century* yint) yint))
|
||||
month
|
||||
day
|
||||
;; when given a full date format, format the date part
|
||||
(when (and (assoc :year format)
|
||||
(assoc :month format)
|
||||
(assoc :day format))
|
||||
(format s "~a-~a-~a "
|
||||
(let ((yint (parse-integer year)))
|
||||
;; process 2-digits year formats specially
|
||||
(if (<= (length year) 2) (+ *century* yint) yint))
|
||||
month
|
||||
day))
|
||||
|
||||
;; now format the time part
|
||||
(format s "~a:~a:~a"
|
||||
(let ((hint (parse-integer hour)))
|
||||
(cond ((and am (= hint 12)) "00")
|
||||
((and pm (= hint 12)) "12")
|
||||
@ -55,6 +62,8 @@
|
||||
(t hour)))
|
||||
minute
|
||||
seconds)
|
||||
|
||||
;; and maybe format the micro seconds part
|
||||
(if usecs (format s ".~a" usecs)
|
||||
(when msecs (format s ".~a" msecs)))))))))
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
LOAD CSV
|
||||
FROM inline ("row num", ts [date format 'YYYY-MM-DD HH24-MI-SS.US'])
|
||||
INTO postgresql:///pgloader?dateformat ("row num", ts)
|
||||
FROM inline
|
||||
(
|
||||
"row num",
|
||||
ts [date format 'YYYY-MM-DD HH24-MI-SS.US'],
|
||||
hr [date format 'HH24.MI.SS']
|
||||
)
|
||||
INTO postgresql:///pgloader?dateformat ("row num", ts, hr)
|
||||
|
||||
WITH truncate,
|
||||
fields optionally enclosed by '"',
|
||||
@ -15,10 +20,11 @@ LOAD CSV
|
||||
$$ drop table if exists dateformat; $$,
|
||||
$$ create table dateformat (
|
||||
"row num" smallint,
|
||||
ts timestamp
|
||||
ts timestamptz,
|
||||
hr time
|
||||
);
|
||||
$$;
|
||||
|
||||
1,1999-10-02 00-33-12.123456
|
||||
2,2014-10-02 00-33-13.123456
|
||||
3,2014-10-02 00-33-14.123456
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user