pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: COPY and custom datestyles. Or some other technique?
Date: Wed, 29 Mar 2023 16:40:49 -0700
Message-ID: <a39bee57-813f-6423-008b-4271a147ba54@aklaver.com> (raw)
In-Reply-To: <9aa715ce-9485-638f-6567-e642a50699c4@aklaver.com>
References: <c1b6aa5b-61ca-1ab6-6295-172fbc0f6c21@gmail.com>
	<9aa715ce-9485-638f-6567-e642a50699c4@aklaver.com>

On 3/29/23 16:31, Adrian Klaver wrote:
> On 3/29/23 16:24, Ron wrote:
>> Postgresql 13.10
>>
>> $ psql -h myhost.example.com -X dba \
>>          -c "\copy ${tbl} from '/var/lib/pgsql/Rdb/${tbl}.csv' WITH 
>> DELIMITER '|';"
>> ERROR:  date/time field value out of range: "2013061914122501"
>> CONTEXT:  COPY t_id_master, line 1, column update_timestamp: 
>> "2013061914122501"
>>
>> The timestamp format generated by a legacy dbms is YYYYMMDDHHmmSSCC 
>> (year to centisecond, with no delimiters).
>>
>> Is there any way to convince Postgresql to import these fields?
> 
> One option:
> 
> 1) Import into staging table as varchar field.
> 
> 2) Use to_timestamp()(NOTE change in template pattern) from here:
> 
> https://www.postgresql.org/docs/current/functions-formatting.html
> 
> select to_timestamp('2013061914122501', 'YYYYMMDDHH24miSSCC');
>        to_timestamp
> -------------------------
>   06/19/2013 14:12:25 PDT

Actually it probably should be:

select to_timestamp('2013061914122501', 'YYYYMMDDHH24miSSMS');
         to_timestamp
----------------------------
  06/19/2013 14:12:25.01 PDT

> 
> to move the data into final table.
> 
>>
>> There are 550+ tables, so something that I can do once on this end 
>> would make my life a lot easier.
>>
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (9+ messages)  latest in thread

Message-ID: <a39bee57-813f-6423-008b-4271a147ba54@aklaver.com>
Permalink:  ../a39bee57-813f-6423-008b-4271a147ba54@aklaver.com/
Also on:    postgresql.org/message-id/a39bee57-813f-6423-008b-4271a147ba54@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, ronljohnsonjr@gmail.com
  Subject: Re: COPY and custom datestyles. Or some other technique?
  In-Reply-To: <a39bee57-813f-6423-008b-4271a147ba54@aklaver.com>
  References: <c1b6aa5b-61ca-1ab6-6295-172fbc0f6c21@gmail.com> <9aa715ce-9485-638f-6567-e642a50699c4@aklaver.com> <a39bee57-813f-6423-008b-4271a147ba54@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox