文档 / 函数百科 / JSON 函数和操作符
FUNCTIONJSON 函数和操作符
jsonb_path_query_first
为指定的JSON值返回由JSON路径返回的第一个JSON项。
Returns the first JSON item returned by the JSON path for the specified JSON value, or NULL if there are no results.
JSON 函数和操作符 引入 12 现存至 20 devel 1 条签名 0 次签名变更
- 分组
- JSON 函数和操作符
- 签名数
- 1 条
- 引入版本
- 12
- 状态
- 现存
- 签名变更
- 未变过
- 本版来源
- 本站译文
版本轨迹
相对 PostgreSQL 17 无变化。
签名
PostgreSQL 18 里 jsonb_path_query_first 的 1 条签名,按上游手册顺序排列。参数名用斜体,类型用弱化色, 之后是返回类型。说明取自本站手册译文:标「沿用」的借用了另一版的译文,标「EN」的本站暂无译文、按英文原文显示。
-
jsonb_path_query_first(targetjsonb,pathjsonpath[,varsjsonb[,silentboolean]] ) →jsonb为指定的JSON值返回由JSON路径返回的第一个JSON项。如果没有结果则返回NULL。 可选的vars和silent参数的作用与jsonb_path_exists相同。jsonb_path_query_first('{"a":[1,2,3,4,5]}', '$.a[*] ? (@ >= $min && @ <= $max)', '{"min":2, "max":4}')2
演化历史
相邻两个大版本之间的差异,新的在前。版本号链到该版的签名。
-
PostgreSQL 17 ← 16 说明更新
说明更新
-
PostgreSQL 13 ← 12 手册重排
这一跳手册重排了函数表的写法,签名文本整体改写,只记函数的增删,不逐条比较签名。
-
PostgreSQL 12 ← 11 新增此函数
PostgreSQL 12 起可用
签名矩阵
每条签名在给出了签名的 9 个版本里的存在情况;方格指向该版的签名。只在正文里提到此函数、没有给出签名的版本不列进来,上面的版本轨迹里仍然有它们。签名文本在 PostgreSQL 13 前后写法不同,跨越那一跳的同一条签名会显示成两行。
存在 不存在
同组函数
| 函数 | 签名 | 主签名 | 版本变动 | 最近变更 |
|---|---|---|---|---|
array_to_json |
1 | array_to_json ( anyarray [, boolean ] ) → json |
9.42 次 | |
| 将SQL数组转换为JSON数组。 | 现存 | |||
json |
1 | json ( expression [ FORMAT JSON [ ENCODING UTF8 ]] [ { WITH | WITHOUT } UNIQUE [ KEYS ]] ) → json |
— | |
| 将按 UTF8 编码的 text 或 bytea 字符串形式指定的给定表达式转换为 JSON 值。 | 现存 | |||
json_array |
2 | json_array ( [ { value_expression [ FORMAT JSON ] } [, ...] ] [ { NULL | ABSENT } ON NULL ] [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ]) |
— | |
| 根据一系列value_expression参数或query_expression的结果构造 JSON 数组;后者必须是只返回一列的 SELECT 查询。 | 现存 | |||
json_array_elements |
1 | json_array_elements ( json ) → setof json |
9.41 次 | |
| 将顶级JSON数组展开为一组JSON值。 | 现存 | |||
json_array_elements_text |
1 | json_array_elements_text ( json ) → setof text |
— | |
| 将顶级 JSON 数组展开为一组text值。 | 现存 | |||
json_array_length |
1 | json_array_length ( json ) → integer |
— | |
| 返回顶层JSON数组中的元素数量。 | 现存 | |||
json_build_array |
1 | json_build_array ( VARIADIC "any" ) → json |
— | |
| 根据可变参数列表构建可能异构类型的JSON数组。 | 现存 | |||
json_build_object |
1 | json_build_object ( VARIADIC "any" ) → json |
— | |
| 根据可变参数列表构建一个JSON对象。 | 现存 | |||
json_each |
1 | json_each ( json ) → setof record ( key text, value json ) |
9.41 次 | |
| 将顶级JSON对象展开为一组键/值对。 | 现存 | |||
json_each_text |
1 | json_each_text ( json ) → setof record ( key text, value text ) |
9.41 次 | |
| 将顶级 JSON 对象展开为一组键/值对。 | 现存 | |||
JSON_EXISTS |
1 | JSON_EXISTS ( context_item, path_expression [PASSING { value AS varname } [, ...]] [{ TRUE | FALSE | UNKNOWN | ERROR } ON ERROR]) → boolean |
— | |
| 暂无一句话说明 | 现存 | |||
json_extract_path |
1 | json_extract_path ( from_json json, VARIADIC path_elems text[] ) → json |
9.41 次 | |
| 在指定路径下提取JSON子对象。 | 现存 | |||
json_extract_path_text |
1 | json_extract_path_text ( from_json json, VARIADIC path_elems text[] ) → text |
— | |
| 将指定路径上的 JSON 子对象提取为text。 | 现存 | |||
json_object |
3 | json_object ( [ { key_expression { VALUE | ':' } value_expression [ FORMAT JSON [ ENCODING UTF8 ] ] }[, ...] ] [ { NULL | ABSENT } ON NULL ] [ { WITH | WITHOUT } UNIQUE [ KEYS ] ] [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ]) |
161 次 | |
| 从文本数组构建JSON对象。 | 现存 | |||
json_object_keys |
1 | json_object_keys ( json ) → setof text |
9.41 次 | |
| 返回顶级JSON对象中的键集合。 | 现存 | |||
json_populate_record |
1 | json_populate_record ( base anyelement, from_json json ) → anyelement |
9.41 次 | |
| 将顶级 JSON 对象展开为具有 base 参数复合类型的行。 | 现存 | |||
json_populate_recordset |
1 | json_populate_recordset ( base anyelement, from_json json ) → setof anyelement |
9.41 次 | |
| 将对象的顶级 JSON 数组展开为一组具有 base 参数复合类型的行。 | 现存 | |||
JSON_QUERY |
1 | JSON_QUERY ( context_item, path_expression [PASSING { value AS varname } [, ...]] [RETURNING data_type [FORMAT JSON [ENCODING UTF8] ] ] [ { WITHOUT | WITH { CONDITIONAL | [UNCONDITIONAL] } } [ARRAY] WRAPPER] [ { KEEP | OMIT } QUOTES [ON SCALAR STRING] ] [ { ERROR | NULL | EMPTY { [ARRAY] | OBJECT } | DEFAULT expression } ON EMPTY] [ { ERROR | NULL | EMPTY { [ARRAY] | OBJECT } | DEFAULT expression } ON ERROR]) → jsonb |
— | |
| 暂无一句话说明 | 现存 | |||
json_scalar |
1 | json_scalar ( expression ) |
— | |
| 将给定的 SQL 标量值转换为 JSON 标量值。 | 现存 | |||
json_serialize |
1 | json_serialize ( expression [ FORMAT JSON [ ENCODING UTF8 ] ] [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ] ) |
— | |
| 将 SQL/JSON 表达式转换为字符或二进制字符串。 | 现存 | |||
json_strip_nulls |
1 | json_strip_nulls ( target json [,strip_in_arrays boolean ] ) → json |
181 次 | |
| 递归地删除给定 JSON 值中所有值为 null 的对象字段。 | 现存 | |||
JSON_TABLE |
1 | JSON_TABLE ( context_item, path_expression [ AS json_path_name] [ PASSING { value AS varname } [, ...] ] COLUMNS ( json_table_column [, ...] ) [ PLAN ( json_table_plan ) | PLAN DEFAULT ( { OUTER | INNER } [ , { CROSS | UNION } ] | { CROSS | UNION } [ , { OUTER | INNER } ] ) ] [ { ERROR | EMPTY [ARRAY]} ON ERROR] ) |
201 次 | |
| 下面更详细地说明每个语法元素。 | 现存 | |||
json_to_record |
1 | json_to_record ( json ) → record |
— | |
| 将顶级JSON对象展开为具有由 AS子句定义的复合类型的行。 | 现存 | |||
json_to_recordset |
1 | json_to_recordset ( json ) → setof record |
— | |
| 将顶级JSON对象数组展开为一组由AS子句定义的复合类型的行。 | 现存 | |||
json_typeof |
1 | json_typeof ( json ) → text |
— | |
| 以文本字符串形式返回顶级JSON值的类型。 | 现存 | |||
JSON_VALUE |
1 | JSON_VALUE ( context_item, path_expression [PASSING { value AS varname } [, ...]] [RETURNING data_type] [ { ERROR | NULL | DEFAULT expression } ON EMPTY] [ { ERROR | NULL | DEFAULT expression } ON ERROR]) → text |
— | |
| 暂无一句话说明 | 现存 | |||
jsonb_array_elements |
1 | jsonb_array_elements ( jsonb ) → setof jsonb |
— | |
| 将顶级JSON数组展开为一组JSON值。 | 现存 | |||
jsonb_array_elements_text |
1 | jsonb_array_elements_text ( jsonb ) → setof text |
— | |
| 将顶级 JSON 数组展开为一组text值。 | 现存 | |||
jsonb_array_length |
1 | jsonb_array_length ( jsonb ) → integer |
— | |
| 返回顶层JSON数组中的元素数量。 | 现存 | |||
jsonb_build_array |
1 | jsonb_build_array ( VARIADIC "any" ) → jsonb |
— | |
| 根据可变参数列表构建可能异构类型的JSON数组。 | 现存 | |||
jsonb_build_object |
1 | jsonb_build_object ( VARIADIC "any" ) → jsonb |
— | |
| 根据可变参数列表构建一个JSON对象。 | 现存 | |||
jsonb_each |
1 | jsonb_each ( jsonb ) → setof record ( key text, value jsonb ) |
— | |
| 将顶级JSON对象展开为一组键/值对。 | 现存 | |||
jsonb_each_text |
1 | jsonb_each_text ( jsonb ) → setof record ( key text, value text ) |
— | |
| 将顶级 JSON 对象展开为一组键/值对。 | 现存 | |||
jsonb_extract_path |
1 | jsonb_extract_path ( from_json jsonb, VARIADIC path_elems text[] ) → jsonb |
— | |
| 在指定路径下提取JSON子对象。 | 现存 | |||
jsonb_extract_path_text |
1 | jsonb_extract_path_text ( from_json jsonb, VARIADIC path_elems text[] ) → text |
— | |
| 将指定路径上的 JSON 子对象提取为text。 | 现存 | |||
jsonb_insert |
1 | jsonb_insert ( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb |
— | |
| 返回插入new_value的target。 | 现存 | |||
jsonb_object |
2 | jsonb_object ( text[] ) → jsonb |
— | |
| 从文本数组构建JSON对象。 | 现存 | |||
jsonb_object_keys |
1 | jsonb_object_keys ( jsonb ) → setof text |
— | |
| 返回顶级JSON对象中的键集合。 | 现存 | |||
jsonb_path_exists |
1 | jsonb_path_exists ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean |
— | |
| 检查JSON路径是否返回指定JSON值的任何项。 | 现存 | |||
jsonb_path_exists_tz |
1 | jsonb_path_exists_tz ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean |
— | |
| 这些函数的作用类似于上面描述的没有_tz后缀的对应函数,不同之处在于这些函数支持需要时区感知转换的日期/时间值的比较。 | 现存 | |||
jsonb_path_match |
1 | jsonb_path_match ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean |
— | |
| 返回指定JSON值的JSON路径谓词检查的结果。 | 现存 | |||
jsonb_path_match_tz |
1 | jsonb_path_match_tz ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean |
— | |
| 这些函数的作用类似于上面描述的没有_tz后缀的对应函数,不同之处在于这些函数支持需要时区感知转换的日期/时间值的比较。 | 现存 | |||
jsonb_path_query |
1 | jsonb_path_query ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → setof jsonb |
— | |
| 为指定的JSON值返回由JSON路径返回的所有JSON项。 | 现存 | |||
jsonb_path_query_array |
1 | jsonb_path_query_array ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb |
— | |
| 以JSON数组的形式返回由JSON路径为指定的JSON值返回的所有JSON项。 | 现存 | |||
jsonb_path_query_array_tz |
1 | jsonb_path_query_array_tz ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb |
— | |
| 这些函数的作用类似于上面描述的没有_tz后缀的对应函数,不同之处在于这些函数支持需要时区感知转换的日期/时间值的比较。 | 现存 | |||
jsonb_path_query_first |
1 | jsonb_path_query_first ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb |
— | |
| 为指定的JSON值返回由JSON路径返回的第一个JSON项。 | 现存 | |||
jsonb_path_query_first_tz |
1 | jsonb_path_query_first_tz ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → jsonb |
— | |
| 这些函数的作用类似于上面描述的没有_tz后缀的对应函数,不同之处在于这些函数支持需要时区感知转换的日期/时间值的比较。 | 现存 | |||
jsonb_path_query_tz |
1 | jsonb_path_query_tz ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → setof jsonb |
— | |
| 这些函数的作用类似于上面描述的没有_tz后缀的对应函数,不同之处在于这些函数支持需要时区感知转换的日期/时间值的比较。 | 现存 | |||
jsonb_populate_record |
1 | jsonb_populate_record ( base anyelement, from_json jsonb ) → anyelement |
— | |
| 将顶级 JSON 对象展开为具有 base 参数复合类型的行。 | 现存 | |||
jsonb_populate_record_valid |
1 | jsonb_populate_record_valid ( base anyelement, from_json json ) → boolean |
— | |
| 用于测试jsonb_populate_record。 | 现存 | |||
jsonb_populate_recordset |
1 | jsonb_populate_recordset ( base anyelement, from_json jsonb ) → setof anyelement |
— | |
| 将对象的顶级 JSON 数组展开为一组具有 base 参数复合类型的行。 | 现存 | |||
jsonb_pretty |
1 | jsonb_pretty ( jsonb ) → text |
— | |
| 将给定的JSON值转换为精美打印的,缩进的文本。 | 现存 | |||
jsonb_set |
1 | jsonb_set ( target jsonb, path text[], new_value jsonb [, create_if_missing boolean ] ) → jsonb |
— | |
| 返回target,将path指定的项替换为new_value, 如果create_if_missing为真(此为默认值)并且path指定的项不存在,则添加new_value。 | 现存 | |||
jsonb_set_lax |
1 | jsonb_set_lax ( target jsonb, path text[], new_value jsonb [, create_if_missing boolean [, null_value_treatment text ]] ) → jsonb |
— | |
| 如果new_value不是NULL,则行为与jsonb_set完全相同。 | 现存 | |||
jsonb_strip_nulls |
1 | jsonb_strip_nulls ( target jsonb [,strip_in_arrays boolean ] ) → jsonb |
181 次 | |
| 递归地删除给定 JSON 值中所有值为 null 的对象字段。 | 现存 | |||
jsonb_to_record |
1 | jsonb_to_record ( jsonb ) → record |
— | |
| 将顶级JSON对象展开为具有由 AS子句定义的复合类型的行。 | 现存 | |||
jsonb_to_recordset |
1 | jsonb_to_recordset ( jsonb ) → setof record |
— | |
| 将顶级JSON对象数组展开为一组由AS子句定义的复合类型的行。 | 现存 | |||
jsonb_typeof |
1 | jsonb_typeof ( jsonb ) → text |
— | |
| 以文本字符串形式返回顶级JSON值的类型。 | 现存 | |||
row_to_json |
1 | row_to_json ( record [, boolean ] ) → json |
9.42 次 | |
| 将SQL组合值转换为JSON对象。 | 现存 | |||
to_json |
1 | to_json ( anyelement ) → json |
9.41 次 | |
| 将任何SQL值转换为json或jsonb。 | 现存 | |||
to_jsonb |
1 | to_jsonb ( anyelement ) → jsonb |
— | |
| 将任何SQL值转换为json或jsonb。 | 现存 | |||