I have a csv file with several columns having a datetime value with a format like this: ‘2008-12-03-18.01.46.000916’. I am trying to import the data using the import capability built in DBeaver and also using postgresql COPY statement. Both fail.
I am using ‘yyyy-MM-dd-HH.mm.ss.SSS’ as import format in DBeaver and I don’t see a way to tell COPY to use a datetime format to read it. I tried DATEFORMAT as you see here but it doesn’t work:
COPY myTable FROM '/tmp/myDataWithDotsInTime.csv'
WITH (FORMAT csv, HEADER false, DELIMITER ',', DATEFORMAT 'yyyy-MM-dd-HH.mm.ss');
Postgresql function to_datetime uses a different format than DBeaver and works, but I don’t find a way to tell COPY to use it:
SELECT CURRENT_TIMESTAMP, to_timestamp('2008-12-03-18.01.46.000916', 'YYYY-MM-DD-HH24.MI.SS') AS ts
2
Answers
I was able to use DBeaver by adding extra SSS in the format for the microseconds in the end (in the import settings) to meet the input criteria like this:
Thanks to DBeaver support person.
Also thanks to Stefanov.sm for your work-around solution that works with the COPY statement. However, In my case I prefer the DBeaver solution because I can import my CSV file from my PC instead of having to copy the CSV file to the Linux back-end to use COPY.
In similar cases (specific formats or a transformation is needed) I use the approach below, generic enough and usually solves the issue.
mytable
with the timestamp column as text;copy
into the temporary table;insert
intomytable
with a select from temporary table.Assuming that the target field in
mytable
ists