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 1jZdCA-0003xp-SR for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 16:28:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZdBd-0004xJ-V6 for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 16:27:49 +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 1jZdBd-0004wb-N1 for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 16:27:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZdBW-0006lI-QB for pgsql-general@postgresql.org; Fri, 15 May 2020 16:27:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 04FGReWE012006; Fri, 15 May 2020 12:27:40 -0400 From: Tom Lane To: PegoraroF10 cc: pgsql-general@postgresql.org Subject: Re: Bug on version 12 ? In-reply-to: <1589555314264-0.post@n3.nabble.com> References: <1589555314264-0.post@n3.nabble.com> Comments: In-reply-to PegoraroF10 message dated "Fri, 15 May 2020 08:08:34 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12004.1589560060.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 15 May 2020 12:27:40 -0400 Message-ID: <12005.1589560060@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PegoraroF10 writes: > select = > JS ->> 'mydate'::text, = > to_timestamp((JS ->> 'mydate'), 'YYYY-MM-DD HH24:MI:SS') > from (select '{"somefield": true, "otherfield": true, "mydate": > "2020-04-02T18:26:50.941531-03:00"}'::jsonb) j(JS) > This SQL works fine on 11.7 but not on 12.3 version. Stripping away the JSON frippery, what you have is to_timestamp('2020-04-02T18:26:50.941531-03:00', 'YYYY-MM-DD HH24:MI:SS') which used to be allowed, but v12 is pickier; it insists that you account for the "T" explicitly: regression=3D# select to_timestamp('2020-04-02T18:26:50.941531-03:00', 'YY= YY-MM-DD HH24:MI:SS'); ERROR: invalid value "T1" for "HH24" DETAIL: Value must be an integer. regression=3D# select to_timestamp('2020-04-02T18:26:50.941531-03:00', 'YY= YY-MM-DDTHH24:MI:SS'); to_timestamp = ------------------------ 2020-04-02 00:06:50-04 (1 row) I think you're doing it wrong and you should just cast to timestamp: regression=3D# select = JS ->> 'mydate'::text, = (JS ->> 'mydate')::timestamptz from (select '{"somefield": true, "otherfield": true, "mydate": "2020-04-02T18:26:50.941531-03:00"}'::jsonb) j(JS) ; ?column? | timestamptz = ----------------------------------+------------------------------- 2020-04-02T18:26:50.941531-03:00 | 2020-04-02 17:26:50.941531-04 (1 row) Use of to_timestamp() to parse a bog-standard time format is a classic antipattern IMO. It is inflexible, it doesn't detect the errors you'd actually like it to detect, and it is harder to type --- so why do people insist on doing it like that? regards, tom lane