pgloader/test/csv-parse-date.load
Dimitri Fontaine b4b36caa84 Fix parsing dates with less-than 4 digits, fix #266.
The previous coding decided to add 2000 to the year as an integer if it
was below 2000, which parses 1999 as 3999. Oops. Trigger the correction
only when the date is given on 2 digits only, parsing 04 as 2004.

Dates given on 3 digits are kept as-is.

Playing with the *century* special parameter allows to cancel this
behavior, that maybe should be made entirely optional. It's just too
common to find current years on 2 digits only, sadly.
2015-07-26 14:41:44 +02:00

25 lines
648 B
Fish

LOAD CSV
FROM inline (rownum, ts [date format 'YYYY-MM-DD HH24-MI-SS.US'])
INTO postgresql:///pgloader?dateformat (rownum, ts)
WITH truncate,
fields optionally enclosed by '"',
fields escaped by double-quote,
fields terminated by ','
SET client_encoding to 'latin1',
work_mem to '12MB',
standard_conforming_strings to 'on'
BEFORE LOAD DO
$$ drop table if exists dateformat; $$,
$$ create table dateformat (
rownum smallint,
ts timestamp
);
$$;
1,1999-10-02 00-33-12.123456
2,2014-10-02 00-33-13.123456
3,2014-10-02 00-33-14.123456