Re: CSV From Oracle with timestamp column getting errors

From: Victor Yegorov <vyegorov(at)gmail(dot)com>
To: "Saha, Sushanta K" <sushanta(dot)saha(at)verizonwireless(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: CSV From Oracle with timestamp column getting errors
Date: 2021-03-22 20:47:08
Message-ID: CAGnEbogPvVfK+xcpKS3A+kinVMf0m895eaR_Y4sTLaH56YVvyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

пн, 22 мар. 2021 г. в 21:38, Saha, Sushanta K <
sushanta(dot)saha(at)verizonwireless(dot)com>:

> \COPY table1 FROM '/tmp/Oracle_2020_06.csv' DELIMITER ',' CSV HEADER;
> ERROR: invalid input syntax for type timestamp: "01-JUN-20
> 06.04.20.634000 AM"
> CONTEXT: COPY table1, line 2, column last_update_timestamp: "01-JUN-20
> 06.04.20.634000 AM"
>
> Appreciate any help with this psql command.
>

I would recommend issuing one of these on the Oracle side *before* taking
the CSV snapshot.
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS';

Otherwise, you have to load this CSV file in a table, that has `text` type
for the column and do a post-processing,
smth like:

INSERT INTO permanent_tab
SELECT *, to_timestamp(col, 'DD-MON-YY HH12.MI.SS.SSSSS AM') FROM
temp_table;

Hope this helps.

--
Victor Yegorov

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Cross 2021-03-22 20:56:42 Re: CSV From Oracle with timestamp column getting errors
Previous Message Saha, Sushanta K 2021-03-22 20:42:02 Re: CSV From Oracle with timestamp column getting errors