Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phfPS-0006Si-Q3 for pgsql-general@arkaria.postgresql.org; Wed, 29 Mar 2023 23:40:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phfPR-0001qX-Mj for pgsql-general@arkaria.postgresql.org; Wed, 29 Mar 2023 23:40:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phfPR-0001qN-Bu for pgsql-general@lists.postgresql.org; Wed, 29 Mar 2023 23:40:53 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phfPO-00043X-Uv for pgsql-general@lists.postgresql.org; Wed, 29 Mar 2023 23:40:52 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6076A5C011B; Wed, 29 Mar 2023 19:40:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 29 Mar 2023 19:40:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1680133250; x=1680219650; bh=YbQka1zgBgbb2WfjbyKN/YwCpQAVebkWFcf D9rgV7mg=; b=LGEKGBAcsB4Y7GVKRQeOaEcucTyFKqvW5ezixCssb9WBDPdpgkk D7QtwOzoGuMgKb/CW5IbaKdZsYoVX+SF2JalPzr9AuX5n1GpxPdVSwT6xtX0XZDf tMLQatlCRXZf3bJp5WSssai+yg8WWWc76W0oY6pPrFXs7KZpVHIYIRX64yUQr7fh CXQv3awHLkWKZZuLznfxAZ6nYXuHO1QHMuYNdw1ifvvK7wABxOR2cRdC5+qD6Rca w5iMvwASi9zYaFeowdLFKykRAnyEKuYIYOiHG8pHp6tZgOEV19G4y7C6g2Ww7MS6 cyTTmm0JrXUF24ASc8CZSPDEFPcp5pnYn+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1680133250; x= 1680219650; bh=YbQka1zgBgbb2WfjbyKN/YwCpQAVebkWFcfD9rgV7mg=; b=g wRO5eiaI0Qx18rw2TjivX98RAubUpC5RTAkqNodf0ML21xOYiJJTOU6e6NDXi8Un YgSqJfpiFu4ntqJPBDK/tF1guQaQM6TEpRFwlTArI4hQmM8laKl/MEgoxDbl4N16 liWiyO66Mg2GbmAVow/PJGWDowvAoAUaS3TCcr4aQyR7iyYsKsmMJB8XUpzIbTeB RGz8J/koRSOoJJprB93ATzi3Mejd9ajLZSK+KJCiY7Bk3+DcQocXjYcJOYgCG9UP NErPr5yKyolUc1zrTt65sC7rCZReRxlcNstmmwqG3X5Wvvvyh+xBsUJUV+euCuia hgmznAN7/ctpUONU8KIrw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehjedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuhffvfhgjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepuedvfeekhe dttdffudekffeghfejuddvleefffejheegveegffffhfffteevgfdunecuffhomhgrihhn pegvgigrmhhplhgvrdgtohhmpdhpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghv vghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 Mar 2023 19:40:49 -0400 (EDT) Message-ID: Date: Wed, 29 Mar 2023 16:40:49 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: COPY and custom datestyles. Or some other technique? Content-Language: en-US From: Adrian Klaver To: Ron , pgsql-general@lists.postgresql.org References: <9aa715ce-9485-638f-6567-e642a50699c4@aklaver.com> In-Reply-To: <9aa715ce-9485-638f-6567-e642a50699c4@aklaver.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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