mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +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:
@@ -1722,6 +1722,16 @@ select jsonb_path_query('"12:34:56 +05:20"', '$.datetime("HH24:MI:SS TZH:TZM").t
|
||||
"time with time zone"
|
||||
(1 row)
|
||||
|
||||
select jsonb_path_query('"10-03-2017T12:34:56"', '$.datetime("dd-mm-yyyy\"T\"HH24:MI:SS")');
|
||||
jsonb_path_query
|
||||
-----------------------
|
||||
"2017-03-10T12:34:56"
|
||||
(1 row)
|
||||
|
||||
select jsonb_path_query('"10-03-2017t12:34:56"', '$.datetime("dd-mm-yyyy\"T\"HH24:MI:SS")');
|
||||
ERROR: unmatched format character "T"
|
||||
select jsonb_path_query('"10-03-2017 12:34:56"', '$.datetime("dd-mm-yyyy\"T\"HH24:MI:SS")');
|
||||
ERROR: unmatched format character "T"
|
||||
set time zone '+00';
|
||||
select jsonb_path_query('"10-03-2017 12:34"', '$.datetime("dd-mm-yyyy HH24:MI")');
|
||||
jsonb_path_query
|
||||
@@ -1901,6 +1911,15 @@ select jsonb_path_query('"2017-03-10 12:34:56+3:10"', '$.datetime()');
|
||||
"2017-03-10T12:34:56+03:10"
|
||||
(1 row)
|
||||
|
||||
select jsonb_path_query('"2017-03-10T12:34:56+3:10"', '$.datetime()');
|
||||
jsonb_path_query
|
||||
-----------------------------
|
||||
"2017-03-10T12:34:56+03:10"
|
||||
(1 row)
|
||||
|
||||
select jsonb_path_query('"2017-03-10t12:34:56+3:10"', '$.datetime()');
|
||||
ERROR: datetime format is not recognized: "2017-03-10t12:34:56+3:10"
|
||||
HINT: Use a datetime template argument to specify the input data format.
|
||||
select jsonb_path_query('"12:34:56"', '$.datetime().type()');
|
||||
jsonb_path_query
|
||||
--------------------------
|
||||
|
||||
Reference in New Issue
Block a user