Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres COPY FROM Fails With invalid input syntax for type timestamp

Tags:

postgresql

I have a pipe delimited file that I'm importing into Postgres (9.2.8) using the command:

COPY schema.tablename FROM '/path/to/file.csv' DELIMITERS '|' CSV

It has been working reliably for a while, but just choked on:

Query failed: ERROR: invalid input syntax for type timestamp: "Sep 24 2013 12:00:00:000AM"

That looks like a valid timestamp to me. Any suggestions?

like image 831
user1517922 Avatar asked May 02 '14 21:05

user1517922


1 Answers

It's the last :000 that's messing you up. For whatever reason, the timestamp-formatting gods decreed that milleseconds be delimited with a "." instead of a ":".

jberkus=# select timestamp 'Sep 24 2013 12:00:00:000AM';

ERROR:  invalid input syntax for type timestamp: "Sep 24 2013 12:00:00:000AM"

jberkus=# select timestamp 'Sep 24 2013 12:00:00.000AM';

          timestamp      
    ---------------------
    2013-09-24 00:00:00
    (1 row)
like image 116
FuzzyChef Avatar answered Oct 19 '22 07:10

FuzzyChef