Inconsistent Parsing of Offsets with Seconds

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Inconsistent Parsing of Offsets with Seconds
Date: 2024-06-22 16:25:29
Message-ID: A1454D02-F747-4A1E-8129-F7E940C7E4EB@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

The treatment of timestamptz (and timetz) values with offsets that include seconds seems a bit inconsistent. One can create such timestamps through the input function:

david=# select '2024-06-22T12:35:00+02:30:15'::timestamptz;
timestamptz
------------------------
2024-06-22 10:04:45+00

But the offset seconds are dropped (or rounded away?) by to_timestamp()’s `OF` and `TZ` formats[2]:

david=# select to_timestamp('2024-06-03 12:35:00+02:30:15', 'YYYY-MM-DD HH24:MI:SSOF');
to_timestamp
------------------------
2024-06-03 10:05:00+00

david=# select to_timestamp('2024-06-03 12:35:00+02:30:15', 'YYYY-MM-DD HH24:MI:SSTZ');
to_timestamp
------------------------
2024-06-03 02:05:00-08

The corresponding jsonpath methods don’t like offsets with seconds *at all*:

david=# select jsonb_path_query('"2024-06-03 12:35:00+02:30:15"', '$.datetime("YYYY-MM-DD HH24:MI:SSOF")');
ERROR: trailing characters remain in input string after datetime format

david=# select jsonb_path_query('"2024-06-03 12:35:00+02:30:15"', '$.timestamp_tz()');
ERROR: timestamp_tz format is not recognized: "2024-06-03 12:35:00+02:30:15"

I see from the source[1] that offsets between plus or minus 15:59:59 are allowed; should the `OF` and `TZ formats be able to parse them? Or perhaps there should be a `TZS` format to complement `TZH` and `TZM`?

Best,

David

[1] https://github.com/postgres/postgres/blob/70a845c/src/include/datatype/timestamp.h#L136-L142
[2]: https://www.postgresql.org/docs/16/functions-formatting.html

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2024-06-22 16:32:25 Re: Meson far from ready on Windows
Previous Message Melanie Plageman 2024-06-22 15:53:47 Re: FreezeLimit underflows in pg14 and 15 causing incorrect behavior in heap_prepare_freeze_tuple