@@ -11910,16 +11910,6 @@ table2-mapping
11910
11910
</para>
11911
11911
11912
11912
<itemizedlist>
11913
- <listitem>
11914
- <para>
11915
- <literal>.datetime()</literal> item method is not implemented yet
11916
- mainly because immutable <type>jsonpath</type> functions and operators
11917
- cannot reference session timezone, which is used in some datetime
11918
- operations. Datetime support will be added to <type>jsonpath</type>
11919
- in future versions of <productname>PostgreSQL</productname>.
11920
- </para>
11921
- </listitem>
11922
-
11923
11913
<listitem>
11924
11914
<para>
11925
11915
A path expression can be a Boolean predicate, although the SQL/JSON
@@ -12190,6 +12180,20 @@ table2-mapping
12190
12180
<entry><literal>$.z.abs()</literal></entry>
12191
12181
<entry><literal>0.3</literal></entry>
12192
12182
</row>
12183
+ <row>
12184
+ <entry><literal>datetime()</literal></entry>
12185
+ <entry>Date/time value converted from a string</entry>
12186
+ <entry><literal>["2015-8-1", "2015-08-12"]</literal></entry>
12187
+ <entry><literal>$[*] ? (@.datetime() < "2015-08-2". datetime())</literal></entry>
12188
+ <entry><literal>2015-8-1</literal></entry>
12189
+ </row>
12190
+ <row>
12191
+ <entry><literal>datetime(<replaceable>template</replaceable>)</literal></entry>
12192
+ <entry>Date/time value converted from a string using the specified template</entry>
12193
+ <entry><literal>["12:30", "18:40"]</literal></entry>
12194
+ <entry><literal>$[*].datetime("HH24:MI")</literal></entry>
12195
+ <entry><literal>"12:30:00", "18:40:00"</literal></entry>
12196
+ </row>
12193
12197
<row>
12194
12198
<entry><literal>keyvalue()</literal></entry>
12195
12199
<entry>
@@ -12207,6 +12211,37 @@ table2-mapping
12207
12211
</tgroup>
12208
12212
</table>
12209
12213
12214
+ <note>
12215
+ <para>
12216
+ The result type of <literal>datetime()</literal> and
12217
+ <literal>datetime(<replaceable>template</replaceable>)</literal>
12218
+ methods can be <type>date</type>, <type>timetz</type>, <type>time</type>,
12219
+ <type>timestamptz</type>, or <type>timestamp</type>.
12220
+ Both methods determine the result type dynamically.
12221
+ </para>
12222
+ <para>
12223
+ The <literal>datetime()</literal> method sequentially tries ISO formats
12224
+ for <type>date</type>, <type>timetz</type>, <type>time</type>,
12225
+ <type>timestamptz</type>, and <type>timestamp</type>. It stops on
12226
+ the first matching format and the corresponding data type.
12227
+ </para>
12228
+ <para>
12229
+ The <literal>datetime(<replaceable>template</replaceable>)</literal>
12230
+ method determines the result type by the provided template string.
12231
+ </para>
12232
+ <para>
12233
+ The <literal>datetime()</literal> and
12234
+ <literal>datetime(<replaceable>template</replaceable>)</literal> methods
12235
+ use the same parsing rules as <literal>to_timestamp</literal> SQL
12236
+ function does (see <xref linkend="functions-formatting"/>) with three
12237
+ exceptions. At first, these methods doesn't allow unmatched template
12238
+ patterns. At second, only following separators are allowed in the
12239
+ template string: minus sign, period, solidus, comma, apostrophe,
12240
+ semicolon, colon and space. At third, separators in the template string
12241
+ must exactly match the input string.
12242
+ </para>
12243
+ </note>
12244
+
12210
12245
<table id="functions-sqljson-filter-ex-table">
12211
12246
<title><type>jsonpath</type> Filter Expression Elements</title>
12212
12247
<tgroup cols="5">
@@ -12350,6 +12385,15 @@ table2-mapping
12350
12385
</tbody>
12351
12386
</tgroup>
12352
12387
</table>
12388
+
12389
+ <note>
12390
+ <para>
12391
+ When different date/time values are compared, an implicit cast is
12392
+ applied. A <type>date</type> value can be cast to <type>timestamp</type>
12393
+ or <type>timestamptz</type>, <type>timestamp</type> can be cast to
12394
+ <type>timestamptz</type>, and <type>time</type> — to <type>timetz</type>.
12395
+ </para>
12396
+ </note>
12353
12397
</sect3>
12354
12398
12355
12399
</sect2>
@@ -12582,7 +12626,7 @@ table2-mapping
12582
12626
<para>
12583
12627
The <literal>@?</literal> and <literal>@@</literal> operators suppress
12584
12628
the following errors: lacking object field or array element, unexpected
12585
- JSON item type, and numeric errors.
12629
+ JSON item type, datetime and numeric errors.
12586
12630
This behavior might be helpful while searching over JSON document
12587
12631
collections of varying structure.
12588
12632
</para>
@@ -12851,18 +12895,33 @@ table2-mapping
12851
12895
<indexterm>
12852
12896
<primary>jsonb_path_exists</primary>
12853
12897
</indexterm>
12898
+ <indexterm>
12899
+ <primary>jsonb_path_exists_tz</primary>
12900
+ </indexterm>
12854
12901
<indexterm>
12855
12902
<primary>jsonb_path_match</primary>
12856
12903
</indexterm>
12904
+ <indexterm>
12905
+ <primary>jsonb_path_match_tz</primary>
12906
+ </indexterm>
12857
12907
<indexterm>
12858
12908
<primary>jsonb_path_query</primary>
12859
12909
</indexterm>
12910
+ <indexterm>
12911
+ <primary>jsonb_path_query_tz</primary>
12912
+ </indexterm>
12860
12913
<indexterm>
12861
12914
<primary>jsonb_path_query_array</primary>
12862
12915
</indexterm>
12916
+ <indexterm>
12917
+ <primary>jsonb_path_query_array_tz</primary>
12918
+ </indexterm>
12863
12919
<indexterm>
12864
12920
<primary>jsonb_path_query_first</primary>
12865
12921
</indexterm>
12922
+ <indexterm>
12923
+ <primary>jsonb_path_query_first_tz</primary>
12924
+ </indexterm>
12866
12925
12867
12926
<table id="functions-json-processing-table">
12868
12927
<title>JSON Processing Functions</title>
@@ -13202,6 +13261,9 @@ table2-mapping
13202
13261
<para><literal>
13203
13262
jsonb_path_exists(target jsonb, path jsonpath [, vars jsonb [, silent bool]])
13204
13263
</literal></para>
13264
+ <para><literal>
13265
+ jsonb_path_exists_tz(target jsonb, path jsonpath [, vars jsonb, silent bool])
13266
+ </literal></para>
13205
13267
</entry>
13206
13268
<entry><type>boolean</type></entry>
13207
13269
<entry>
@@ -13222,6 +13284,9 @@ table2-mapping
13222
13284
<para><literal>
13223
13285
jsonb_path_match(target jsonb, path jsonpath [, vars jsonb, silent bool])
13224
13286
</literal></para>
13287
+ <para><literal>
13288
+ jsonb_path_match_tz(target jsonb, path jsonpath [, vars jsonb, silent bool])
13289
+ </literal></para>
13225
13290
</entry>
13226
13291
<entry><type>boolean</type></entry>
13227
13292
<entry>
@@ -13243,6 +13308,9 @@ table2-mapping
13243
13308
<para><literal>
13244
13309
jsonb_path_query(target jsonb, path jsonpath [, vars jsonb, silent bool])
13245
13310
</literal></para>
13311
+ <para><literal>
13312
+ jsonb_path_query_tz(target jsonb, path jsonpath [, vars jsonb, silent bool])
13313
+ </literal></para>
13246
13314
</entry>
13247
13315
<entry><type>setof jsonb</type></entry>
13248
13316
<entry>
@@ -13271,6 +13339,9 @@ table2-mapping
13271
13339
<para><literal>
13272
13340
jsonb_path_query_array(target jsonb, path jsonpath [, vars jsonb, silent bool])
13273
13341
</literal></para>
13342
+ <para><literal>
13343
+ jsonb_path_query_array_tz(target jsonb, path jsonpath [, vars jsonb, silent bool])
13344
+ </literal></para>
13274
13345
</entry>
13275
13346
<entry><type>jsonb</type></entry>
13276
13347
<entry>
@@ -13291,6 +13362,9 @@ table2-mapping
13291
13362
<para><literal>
13292
13363
jsonb_path_query_first(target jsonb, path jsonpath [, vars jsonb, silent bool])
13293
13364
</literal></para>
13365
+ <para><literal>
13366
+ jsonb_path_query_first_tz(target jsonb, path jsonpath [, vars jsonb, silent bool])
13367
+ </literal></para>
13294
13368
</entry>
13295
13369
<entry><type>jsonb</type></entry>
13296
13370
<entry>
@@ -13433,11 +13507,8 @@ table2-mapping
13433
13507
13434
13508
<note>
13435
13509
<para>
13436
- The <literal>jsonb_path_exists</literal>, <literal>jsonb_path_match</literal>,
13437
- <literal>jsonb_path_query</literal>, <literal>jsonb_path_query_array</literal>, and
13438
- <literal>jsonb_path_query_first</literal>
13439
- functions have optional <literal>vars</literal> and <literal>silent</literal>
13440
- arguments.
13510
+ The <literal>jsonb_path_*</literal> functions have optional
13511
+ <literal>vars</literal> and <literal>silent</literal> arguments.
13441
13512
</para>
13442
13513
<para>
13443
13514
If the <parameter>vars</parameter> argument is specified, it provides an
@@ -13451,6 +13522,20 @@ table2-mapping
13451
13522
</para>
13452
13523
</note>
13453
13524
13525
+ <note>
13526
+ <para>
13527
+ Some of the <literal>jsonb_path_*</literal> functions have the
13528
+ <literal>_tz</literal> suffix. These functions have been implemented to
13529
+ support comparison of date/time values that involves implicit
13530
+ timezone-aware casts. Since operations with time zones are not immutable,
13531
+ these functions are qualified as stable. Their counterparts without the
13532
+ suffix do not support such casts, so they are immutable and can be used for
13533
+ such use-cases as expression indexes
13534
+ (see <xref linkend="indexes-expressional"/>). There is no difference
13535
+ between these functions for other <type>jsonpath</type> operations.
13536
+ </para>
13537
+ </note>
13538
+
13454
13539
<para>
13455
13540
See also <xref linkend="functions-aggregate"/> for the aggregate
13456
13541
function <function>json_agg</function> which aggregates record
0 commit comments