It is not really clear how to copy a CSV file that contains unix timestamp values into Postgres. For example, let's say that I have a CSV file that looks like this:
timestamp, column_1, column_2, column_3
1439935260;"A";"B";"C"
1439935261;"A";"B";"C"
1439935262;"A";"B";"C"
I also have a database which has the following columns:
timestamp | timestamp without time zone |
column_1 | character varying(40) |
column_2 | timestamp without time zone |
column_3 | timestamp without time zone |
I would expect the command
\copy my_table FROM 'my_file.csv' DELIMITER ';' CSV HEADER;
to work, yet it doesn't. You would receive the error
ERROR: date/time field value out of range: "1439935260"
What is the proper way to copy CSV files with unix timestamp values into a table?
NEW."timestamp" = to_timestamp(NEW."timestamp")if the purpose of that table is to be always used for suchCOPYimports - Vao Tsun