Skip to content

Document impact of datestyle on jsonpath string() #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/src/sgml/func.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -17971,7 +17971,9 @@ ERROR: jsonpath member accessor can only be applied to an object
<returnvalue><replaceable>string</replaceable></returnvalue>
</para>
<para>
String value converted from a JSON boolean, number, string, or datetime
String value converted from a JSON boolean, number, string, or
datetime. Note that the string output of datetimes is determined by
the <xref linkend="guc-datestyle"/> parameter.
</para>
<para>
<literal>jsonb_path_query_array('[1.23, "xyz", false]', '$[*].string()')</literal>
Expand Down
89 changes: 89 additions & 0 deletions src/test/regress/expected/jsonb_jsonpath.out
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,95 @@ select jsonb_path_query_array('[1.23, "yes", false]', '$[*].string().type()');
["string", "string", "string"]
(1 row)

select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp_tz().string()');
ERROR: cannot convert value from timestamp to timestamptz without time zone usage
HINT: Use *_tz() function for time zone support.
select jsonb_path_query_tz('"2023-08-15 12:34:56"', '$.timestamp_tz().string()'); -- should work
jsonb_path_query_tz
--------------------------------
"Tue Aug 15 12:34:56 2023 PDT"
(1 row)

select jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp_tz().string()');
jsonb_path_query
--------------------------------
"Tue Aug 15 00:04:56 2023 PDT"
(1 row)

select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp().string()');
jsonb_path_query
----------------------------
"Tue Aug 15 12:34:56 2023"
(1 row)

select jsonb_path_query('"12:34:56 +5:30"', '$.time_tz().string()');
jsonb_path_query
------------------
"12:34:56+05:30"
(1 row)

select jsonb_path_query_tz('"12:34:56"', '$.time_tz().string()'); -- should work
jsonb_path_query_tz
---------------------
"12:34:56-07"
(1 row)

select jsonb_path_query('"12:34:56"', '$.time().string()');
jsonb_path_query
------------------
"12:34:56"
(1 row)

select jsonb_path_query('"2023-08-15"', '$.date().string()');
jsonb_path_query
------------------
"08-15-2023"
(1 row)

set datestyle = 'ISO';
select jsonb_path_query_tz('"2023-08-15 12:34:56"', '$.timestamp_tz().string()'); -- should work
jsonb_path_query_tz
--------------------------
"2023-08-15 12:34:56-07"
(1 row)

select jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp_tz().string()');
jsonb_path_query
--------------------------
"2023-08-15 00:04:56-07"
(1 row)

select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp().string()');
jsonb_path_query
-----------------------
"2023-08-15 12:34:56"
(1 row)

select jsonb_path_query('"12:34:56 +5:30"', '$.time_tz().string()');
jsonb_path_query
------------------
"12:34:56+05:30"
(1 row)

select jsonb_path_query_tz('"12:34:56"', '$.time_tz().string()'); -- should work
jsonb_path_query_tz
---------------------
"12:34:56-07"
(1 row)

select jsonb_path_query('"12:34:56"', '$.time().string()');
jsonb_path_query
------------------
"12:34:56"
(1 row)

select jsonb_path_query('"2023-08-15"', '$.date().string()');
jsonb_path_query
------------------
"2023-08-15"
(1 row)

reset datestyle;
-- Test .time()
select jsonb_path_query('null', '$.time()');
ERROR: jsonpath item method .time() can only be applied to a string
Expand Down
18 changes: 18 additions & 0 deletions src/test/regress/sql/jsonb_jsonpath.sql
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,24 @@ select jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp().string()')
select jsonb_path_query_tz('"2023-08-15 12:34:56 +5:30"', '$.timestamp().string()'); -- should work
select jsonb_path_query_array('[1.23, "yes", false]', '$[*].string()');
select jsonb_path_query_array('[1.23, "yes", false]', '$[*].string().type()');
select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp_tz().string()');
select jsonb_path_query_tz('"2023-08-15 12:34:56"', '$.timestamp_tz().string()'); -- should work
select jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp_tz().string()');
select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp().string()');
select jsonb_path_query('"12:34:56 +5:30"', '$.time_tz().string()');
select jsonb_path_query_tz('"12:34:56"', '$.time_tz().string()'); -- should work
select jsonb_path_query('"12:34:56"', '$.time().string()');
select jsonb_path_query('"2023-08-15"', '$.date().string()');

set datestyle = 'ISO';
select jsonb_path_query_tz('"2023-08-15 12:34:56"', '$.timestamp_tz().string()'); -- should work
select jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp_tz().string()');
select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp().string()');
select jsonb_path_query('"12:34:56 +5:30"', '$.time_tz().string()');
select jsonb_path_query_tz('"12:34:56"', '$.time_tz().string()'); -- should work
select jsonb_path_query('"12:34:56"', '$.time().string()');
select jsonb_path_query('"2023-08-15"', '$.date().string()');
reset datestyle;

-- Test .time()
select jsonb_path_query('null', '$.time()');
Expand Down