1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Support for ISO 8601 in the jsonpath .datetime() method

The SQL standard doesn't require jsonpath .datetime() method to support the
ISO 8601 format.  But our to_json[b]() functions convert timestamps to text in
the ISO 8601 format in the sake of compatibility with javascript.  So, we add
support of the  ISO 8601 to the jsonpath .datetime() in the sake compatibility
with to_json[b]().

The standard mode of datetime parsing currently supports just template patterns
and separators in the format string.  In order to implement ISO 8601, we have to
add support of the format string double quotes to the standard parsing mode.

Discussion: https://postgr.es/m/94321be0-cc96-1a81-b6df-796f437f7c66%40postgrespro.ru
Author: Nikita Glukhov, revised by me
Backpatch-through: 13
This commit is contained in:
Alexander Korotkov
2020-09-29 11:41:46 +03:00
parent c2aa562ea5
commit 927d9abb65
4 changed files with 49 additions and 4 deletions

View File

@ -1833,6 +1833,9 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
/*
* According to SQL/JSON standard enumerate ISO formats for: date,
* timetz, time, timestamptz, timestamp.
*
* We also support ISO 8601 for timestamps, because to_json[b]()
* functions use this format.
*/
static const char *fmt_str[] =
{
@ -1842,7 +1845,10 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
"HH24:MI:SS",
"yyyy-mm-dd HH24:MI:SSTZH:TZM",
"yyyy-mm-dd HH24:MI:SSTZH",
"yyyy-mm-dd HH24:MI:SS"
"yyyy-mm-dd HH24:MI:SS",
"yyyy-mm-dd\"T\"HH24:MI:SSTZH:TZM",
"yyyy-mm-dd\"T\"HH24:MI:SSTZH",
"yyyy-mm-dd\"T\"HH24:MI:SS"
};
/* cache for format texts */