pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedBug on version 12 ?
13+ messages / 7 participants
[nested] [flat]
* Bug on version 12 ?
@ 2020-05-15 15:08 PegoraroF10 <marcos@f10.com.br>
2020-05-15 15:26 ` Re: Bug on version 12 ? Michael Lewis <mlewis@entrata.com>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:28 ` Re: Bug on version 12 ? David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 3 replies; 13+ messages in thread
From: PegoraroF10 @ 2020-05-15 15:08 UTC (permalink / raw)
To: pgsql-general
select To_Json(Current_Timestamp);
returns "2020-05-15T14:49:44.266342+00:00" on version 11.7 or 12.3
So I have lots of JSONS which have timestamp on them.
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.
ERROR: invalid value "T1" for "HH24"
Detail: Value must be an integer.
Where: SQL function "castimmutabletimestamp" statement 1
Is that a version 12 bug or a server configuration ?
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-15 15:26 ` Michael Lewis <mlewis@entrata.com>
2020-05-15 16:07 ` Re: Bug on version 12 ? David G. Johnston <david.g.johnston@gmail.com>
2020-05-15 16:09 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2 siblings, 2 replies; 13+ messages in thread
From: Michael Lewis @ 2020-05-15 15:26 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; +Cc: pgsql-general
Just wonder, have you compared these on the two servers?
select * from pg_settings where name = 'DateStyle';
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 15:26 ` Re: Bug on version 12 ? Michael Lewis <mlewis@entrata.com>
@ 2020-05-15 16:07 ` David G. Johnston <david.g.johnston@gmail.com>
1 sibling, 0 replies; 13+ messages in thread
From: David G. Johnston @ 2020-05-15 16:07 UTC (permalink / raw)
To: Michael Lewis <mlewis@entrata.com>; +Cc: PegoraroF10 <marcos@f10.com.br>; pgsql-general
On Fri, May 15, 2020 at 8:27 AM Michael Lewis <mlewis@entrata.com> wrote:
> Just wonder, have you compared these on the two servers?
>
> select * from pg_settings where name = 'DateStyle';
>
The OP is using to_timestamp, the DateStyle setting is immaterial.
David J.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 15:26 ` Re: Bug on version 12 ? Michael Lewis <mlewis@entrata.com>
@ 2020-05-15 16:09 ` PegoraroF10 <marcos@f10.com.br>
1 sibling, 0 replies; 13+ messages in thread
From: PegoraroF10 @ 2020-05-15 16:09 UTC (permalink / raw)
To: pgsql-general
Both are ISO, MDY
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-15 16:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2 siblings, 1 reply; 13+ messages in thread
From: Tom Lane @ 2020-05-15 16:27 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; +Cc: pgsql-general
PegoraroF10 <marcos@f10.com.br> 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=# select to_timestamp('2020-04-02T18:26:50.941531-03:00', 'YYYY-MM-DD HH24:MI:SS');
ERROR: invalid value "T1" for "HH24"
DETAIL: Value must be an integer.
regression=# select to_timestamp('2020-04-02T18:26:50.941531-03:00', 'YYYY-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=# 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
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-05-15 16:38 ` PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:56 ` Re: Bug on version 12 ? John W Higgins <wishdev@gmail.com>
2020-05-15 17:55 ` Re: Bug on version 12 ? Adrian Klaver <adrian.klaver@aklaver.com>
2020-05-15 18:34 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 3 replies; 13+ messages in thread
From: PegoraroF10 @ 2020-05-15 16:38 UTC (permalink / raw)
To: pgsql-general
Ok Tom but then you cannot go back and forth, like this ...
select to_timestamp(jsonb_build_object('mydate',
current_timestamp)->>'mydate', 'YYYY-MM-DD HH24:MI:SS');
works on 11.7 but not on 12.3.
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-15 16:56 ` John W Higgins <wishdev@gmail.com>
2 siblings, 0 replies; 13+ messages in thread
From: John W Higgins @ 2020-05-15 16:56 UTC (permalink / raw)
To: pgsql-general
On Fri, May 15, 2020 at 9:38 AM PegoraroF10 <marcos@f10.com.br> wrote:
> Ok Tom but then you cannot go back and forth, like this ...
>
> select to_timestamp(jsonb_build_object('mydate',
> current_timestamp)->>'mydate', 'YYYY-MM-DD HH24:MI:SS');
>
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-15 17:55 ` Adrian Klaver <adrian.klaver@aklaver.com>
2 siblings, 0 replies; 13+ messages in thread
From: Adrian Klaver @ 2020-05-15 17:55 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; pgsql-general
On 5/15/20 9:38 AM, PegoraroF10 wrote:
> Ok Tom but then you cannot go back and forth, like this ...
>
> select to_timestamp(jsonb_build_object('mydate',
> current_timestamp)->>'mydate', 'YYYY-MM-DD HH24:MI:SS');
select jsonb_build_object('mydate',
current_timestamp);
jsonb_build_object
------------------------------------------------
{"mydate": "2020-05-15T10:54:17.913596-07:00"}
(1 row)
Option 1:
select to_timestamp(jsonb_build_object('mydate',
current_timestamp)->>'mydate', 'YYYY-MM-DD T HH24:MI:SS');
to_timestamp
-------------------------
05/15/2020 10:54:20 PDT
Option 2 per Tom's suggestion:
select (jsonb_build_object('mydate',
current_timestamp)->>'mydate')::timestamptz;
timestamptz
--------------------------------
05/15/2020 10:54:58.649859 PDT
>
> works on 11.7 but not on 12.3.
>
>
>
>
>
> --
> Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-15 18:34 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 19:35 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2 siblings, 1 reply; 13+ messages in thread
From: Tom Lane @ 2020-05-15 18:34 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; +Cc: pgsql-general
PegoraroF10 <marcos@f10.com.br> writes:
> Ok Tom but then you cannot go back and forth, like this ...
> select to_timestamp(jsonb_build_object('mydate',
> current_timestamp)->>'mydate', 'YYYY-MM-DD HH24:MI:SS');
> works on 11.7 but not on 12.3.
The advice I gave you was to stop using to_timestamp altogether.
That would work fine on any Postgres version.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 18:34 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-05-15 19:35 ` PegoraroF10 <marcos@f10.com.br>
2020-05-15 19:57 ` Re: Bug on version 12 ? Adrian Klaver <adrian.klaver@aklaver.com>
2020-05-18 06:49 ` Re: Bug on version 12 ? Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 2 replies; 13+ messages in thread
From: PegoraroF10 @ 2020-05-15 19:35 UTC (permalink / raw)
To: pgsql-general
I understood, but the problem is that I cannot just migrate from 11 to 12, I
have to carefully verify all code before migration.
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 18:34 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 19:35 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-15 19:57 ` Adrian Klaver <adrian.klaver@aklaver.com>
1 sibling, 0 replies; 13+ messages in thread
From: Adrian Klaver @ 2020-05-15 19:57 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; pgsql-general
On 5/15/20 12:35 PM, PegoraroF10 wrote:
> I understood, but the problem is that I cannot just migrate from 11 to 12, I
> have to carefully verify all code before migration.
It would be helpful to include the information you are responding to.
The simplest case works on 11:
select version();
version
---------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 11.8 (Ubuntu 11.8-1.pgdg18.04+1) on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit
select (jsonb_build_object('mydate',
test(# current_timestamp)->>'mydate')::timestamptz;
timestamptz
-------------------------------
2020-05-15 12:55:26.259151-07
(1 row)
>
>
>
> --
> Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 18:34 ` Re: Bug on version 12 ? Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 19:35 ` Re: Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-18 06:49 ` Laurenz Albe <laurenz.albe@cybertec.at>
1 sibling, 0 replies; 13+ messages in thread
From: Laurenz Albe @ 2020-05-18 06:49 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; pgsql-general
On Fri, 2020-05-15 at 12:35 -0700, PegoraroF10 wrote:
> I understood, but the problem is that I cannot just migrate from 11 to 12, I
> have to carefully verify all code before migration.
That is always required. Owing to cour careful testing, you found an
incompatibility, and you have to adapt your code to it.
That said, I feel your pain at this unexpected incompatibility.
We try not to introduce incompatibility if we don't think that the
advantages outweigh the disadvantages, and in this case the new
behavior seems cleaner and following the documentation more closely.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Bug on version 12 ?
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
@ 2020-05-15 16:28 ` David G. Johnston <david.g.johnston@gmail.com>
2 siblings, 0 replies; 13+ messages in thread
From: David G. Johnston @ 2020-05-15 16:28 UTC (permalink / raw)
To: PegoraroF10 <marcos@f10.com.br>; +Cc: pgsql-general
On Fri, May 15, 2020 at 8:08 AM PegoraroF10 <marcos@f10.com.br> wrote:
> select To_Json(Current_Timestamp);
> returns "2020-05-15T14:49:44.266342+00:00" on version 11.7 or 12.3
>
> So I have lots of JSONS which have timestamp on them.
>
> 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.
>
> ERROR: invalid value "T1" for "HH24"
> Detail: Value must be an integer.
> Where: SQL function "castimmutabletimestamp" statement 1
>
> Is that a version 12 bug or a server configuration ?
>
Its a version 12 behavior change, though its somewhat unfortunate that its
covered by the imprecise:
"Adjust to_timestamp()/to_date() functions to be more forgiving of template
mismatches ..." item in the release notes.
I believe (cannot test at the moment) that the issue is that the code no
longer likes to match space template markers with non-space input, skipping
the template position altogether without moving along the input string.
You will want to change your template to use "T" which more closely matches
the input data anwyay.
Order you can, and probably should, just stop using to_timestamp and do
("JS->>'mydate)::timestamptz (which has the added benefit of keeping the
timezone information).
David J.
^ permalink raw reply [nested|flat] 13+ messages in thread
end of thread, other threads:[~2020-05-18 06:49 UTC | newest]
Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 15:08 Bug on version 12 ? PegoraroF10 <marcos@f10.com.br>
2020-05-15 15:26 ` Michael Lewis <mlewis@entrata.com>
2020-05-15 16:07 ` David G. Johnston <david.g.johnston@gmail.com>
2020-05-15 16:09 ` PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 16:38 ` PegoraroF10 <marcos@f10.com.br>
2020-05-15 16:56 ` John W Higgins <wishdev@gmail.com>
2020-05-15 17:55 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-05-15 18:34 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-05-15 19:35 ` PegoraroF10 <marcos@f10.com.br>
2020-05-15 19:57 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-05-18 06:49 ` Laurenz Albe <laurenz.albe@cybertec.at>
2020-05-15 16:28 ` David G. Johnston <david.g.johnston@gmail.com>
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