24
24
25
25
26
26
27
- To learn more about the SQL/JSON standard, see .
28
- For details on JSON types supported in
PostgreSQL , see
.
27
+ To learn more about the SQL/JSON standard, see .
28
+ For details on JSON types supported in
PostgreSQL ,
29
+ see .
29
30
30
31
31
32
@@ -1064,15 +1065,13 @@ SELECT JSON_EXISTS(jsonb '{"a": [1,2,3]}', 'strict $.a[5]');
1064
1065
1065
1066
1066
1067
1067
- The output clause that specifies the data type of the returned value.
1068
- Out of the box,
PostgreSQL
1069
- supports the following types: json , jsonb ,
1070
- bytea , and character string types (text , char ,
1071
- varchar , and nchar ).
1072
- The extracted value must be a single
SQL/JSON scalar item
1073
- and have a cast to the specified type. Otherwise, an error occurs.
1068
+ The output clause that specifies the SQL data type the extracted value
1069
+ will be represented as. The extracted value must be a single
1070
+ SQL/JSON scalar item and have a cast to the
1071
+ specified type. Otherwise, an error occurs.
1074
1072
By default, JSON_VALUE returns a string
1075
- of the text type.
1073
+ of the text type. For details, see
1074
+ .
1076
1075
1077
1076
1078
1077
@@ -1112,11 +1111,10 @@ SELECT JSON_EXISTS(jsonb '{"a": [1,2,3]}', 'strict $.a[5]');
1112
1111
Examples
1113
1112
1114
1113
1115
- Extract an SQL/JSON value and return it as an SQL
1116
- scalar of the specified type. Note that
1117
- JSON_VALUE can only return a
1118
- single scalar, and the returned value must have a
1119
- cast to the specified return type:
1114
+ Extract an SQL/JSON value and return it as an SQL scalar
1115
+ of the specified type. Note that JSON_VALUE
1116
+ can only return a single scalar, and the extracted value must have
1117
+ a cast to the specified return type:
1120
1118
1121
1119
1122
1120
@@ -1226,7 +1224,12 @@ SELECT JSON_VALUE(jsonb '[1,2]', 'strict $[*]' DEFAULT 1 ON ERROR);
1226
1224
1227
1225
1228
1226
1229
- The output clause that specifies the data type of the returned value.
1227
+ The output clause that specifies the SQL data type the extracted
1228
+ SQL/JSON object or array will be represented as. By default,
1229
+ JSON_QUERY returns a string of the
1230
+ json type, unless the context item is explicitly
1231
+ converted to another type. In this case, the return type corresponds
1232
+ to the type of the context item.
1230
1233
For details, see .
1231
1234
1232
1235
@@ -2032,19 +2035,127 @@ FROM
2032
2035
2033
2036
2034
2037
The output clause that specifies the return type of the generated
2035
- JSON object. Out of the box,
PostgreSQL
2036
- supports the following types: json , jsonb ,
2037
- bytea , and character string types (text , char ,
2038
- varchar , and nchar ).
2039
- To use other types, you must create the CAST from json for this type.
2040
- By default, the json type is returned.
2038
+
2041
2039
2040
+
2042
2041
2043
- The optional FORMAT clause is provided to conform to the SQL/JSON standard.
2044
-
2042
+ The RETURNING clause is common for both constructor
2043
+ and query SQL/JSON functions. All functions rely on type casts
2044
+ available in
PostgreSQL , but have some
2045
+ implementation specifics that determines which types can be used
2046
+ by a particular function. Type casts supported by
2047
+ PostgreSQL out of the box are listed
2048
+ in .
2049
+
2050
+
2051
+
2052
+ Constructor functions support json , jsonb ,
2053
+ bytea , and any other types that have a cast from
2054
+ the SQL type of the constructed item. By default,
2055
+ the constructed item is represented as json .
2056
+
2057
+
2045
2058
2046
- The output clause is common for both constructor and query SQL/JSON functions.
2059
+ For the JSON_VALUE function, you can use
2060
+ json , jsonb , or any other type that has
2061
+ a cast from the SQL type that corresponds to the SQL/JSON type of the
2062
+ extracted value. The output to json and jsonb
2063
+ types will always work regardless of the type of the extracted value,
2064
+ since SQL/JSON items are converted directly to json or
2065
+ jsonb without casting. With other types, the result
2066
+ depends on the combination of the type of the extracted value
2067
+ and the specified return type: if no cast is found, an error occurs.
2068
+ By default, the
SQL/JSON item returned by
2069
+ JSON_VALUE is represented as text .
2047
2070
2071
+
2072
+
2073
+ With the JSON_QUERY function, you can use any
2074
+ return types. The implementation details are as follows:
2075
+
2076
+
2077
+
2078
+ For SQL/JSON items of a scalar SQL type, a cast from json
2079
+ or jsonb is searched, depending on the type of the context
2080
+ item. If no cast is found, an input/output function is used for
2081
+ conversion. As an exception, if you use the bytea return
2082
+ type, the extracted SQL/JSON item is converted to the return type as
2083
+ follows: convert_to(json[b]::text, 'UTF8') .
2084
+ If JSON_QUERY extracts an SQL/JSON string,
2085
+ which is not wrapped using the WRAPPER clause,
2086
+ and the OMIT QUOTES clause is specified, the string
2087
+ contents is converted to the return type using the input/output
2088
+ function that corresponds to this return type.
2089
+
2090
+
2091
+
2092
+
2093
+ For SQL/JSON items of non-scalar SQL types (arrays, records, and
2094
+ domains), the json[b]_populate_record() function
2095
+ is used for conversion to the specified return type. This is a
2096
+ PostgreSQL extension of the SQL/JSON standard.
2097
+
2098
+
2099
+
2100
+ By default, JSON_QUERY returns a string of the
2101
+ json type, unless the context item is is explicitly
2102
+ converted to another type. In this case, the return type corresponds
2103
+ to the type of the context item.
2104
+
2105
+
2106
+
2107
+ Type Casts Supported by PostgreSQL
2108
+
2109
+
2110
+ |
2111
+ SQL/JSON type
2112
+ SQL Type
2113
+
2114
+
2115
+
2116
+ |
2117
+ string
2118
+ text
2119
+
2120
+ |
2121
+ number
2122
+ numeric
2123
+
2124
+ |
2125
+ boolean
2126
+ boolean
2127
+
2128
+ |
2129
+ date
2130
+ date
2131
+
2132
+ |
2133
+ time
2134
+ time
2135
+
2136
+ |
2137
+ time with tz
2138
+ timetz
2139
+
2140
+ |
2141
+ timestamp
2142
+ timestamp
2143
+
2144
+ |
2145
+ timestamp with tz
2146
+ timestamptz
2147
+
2148
+
2149
+
2150
+
2151
+
2152
+
2153
+ The optional FORMAT clause is provided
2154
+ to conform to the SQL/JSON standard and can only take the
2155
+ json value as an argument.
2156
+ PostgreSQL currently supports
2157
+ only the UTF8 encoding.
2158
+
2048
2159
2049
2160
2050
2161
@@ -2067,18 +2178,18 @@ FROM
2067
2178
2068
2179
The SQL/JSON query functions pass the provided path expression to
2069
2180
the path engine for evaluation.
2070
- The path expression is evaluated from left to right.
2071
- You can use parentheses to change the order of operations.
2072
- If the evaluation is successful, an SQL/JSON sequence is produced.
2073
- The evaluation result is returned to the SQL/JSON query function
2181
+ The path expression is evaluated from left to right, but
2182
+ you can use parentheses to change the order of operations.
2183
+ If the evaluation is successful, an SQL/JSON sequence is produced,
2184
+ and the evaluation result is returned to the SQL/JSON query function
2074
2185
that completes the specified computation. If the query result
2075
2186
must be JSON text, you have to use the WITH WRAPPER clause
2076
2187
or enclose the path expression in square brackets to ensure
2077
2188
the evaluation result is an array.
2078
2189
2079
2190
2080
2191
2081
- A typical path expression has the following structure:
2192
+ A path expression has the following structure:
2082
2193
2083
2194
2084
2195
@@ -2508,7 +2619,7 @@ FROM
2508
2619
2509
2620
|
2510
2621
like_regex
2511
- Tests pattern matching with regular expressions
2622
+ Tests pattern matching with POSIX regular expressions
2512
2623
["abc", "abd", "aBdC", "abdacb", "babc"]
2513
2624
$[*] ? (@ like_regex "^ab.*c" flag "i")
2514
2625
"abc", "aBdC", "abdacb"
@@ -3545,4 +3656,3 @@ FROM
3545
3656
3546
3657
3547
3658
3548
-
0 commit comments