-
jsonb_insert(target jsonb, path text[], new_value jsonb [, insert_after boolean]) 描述:返回target,并插入new_value。如果path指定的target部分位于JSONB数组中,则new_value将在目标之前或insert_after为true(默认值为false)之后插入。如果在JSONB对象中由path指定的target部分,则仅当target不存在时才插入new_value。与面向路径的运算符一样,path中出现的负整数从JSON数组的末尾开始计数。 返回类型:jsonb 示例: 1
2
3
4
5 SELECT jsonb_insert('{"a": [0,1,2]}', '{a, 1}', '"new_value"');
jsonb_insert
-------------------------------
{"a": [0, "new_value", 1, 2]}
(1 row)
-
json_to_tsvector(config regconfig, ] json, jsonb) 描述:将json格式转换为用于支持全文检索的文件格式tsvector。 返回类型:jsonb 示例: 1
2
3
4
5 SELECT json_to_tsvector('{"a":1, "b":2, "c":3}'::json, to_jsonb('key'::text));
json_to_tsvector
------------------
'b':2 'c':4
(1 row)
-
jsonb_pretty(jsonb) 描述:以缩进的JSON文本形式返回。 返回类型:jsonb 示例: 1
2
3
4
5
6
7
8
9
10
11
12
13 SELECT jsonb_pretty('{"a":{"b":{"c":1, "d":2}}, "e":3}'::jsonb);
jsonb_pretty
---------------------
{ +
"a": { +
"b": { +
"c": 1,+
"d": 2 +
} +
}, +
"e": 3 +
}
(1 row)
-
jsonb_to_record(object-json) 描述:正如所有返回record的函数一样,调用者必须用一个AS子句显式地定义记录的结构。会将object-json的键值对进行拆分重组,把键当做列名,去匹配填充AS显示指定的记录的结构。 返回类型:record 示例: 1
2
3
4
5 SELECT * FROM jsonb_to_record('{"a":1,"b":"foo","c":"bar"}'::jsonb) as x(a int, b text, d text);
a | b | d
---+-----+---
1 | foo |
(1 row)
-
jsonb_to_recordset(array-json) 描述:参考函数jsonb_to_record,对数组内个每个元素,执行上述函数的操作,因此这要求数组内的每个元素都得是object-jsonb。 返回类型:setof record 示例: 1
2
3
4
5
6 SELECT * FROM jsonb_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]') AS x(a INT, b text, c boolean);
a | b | c
---+-----+---
1 | foo |
2 | bar | t
(2 rows)
-
jsonb_exists_any(jsonb, text[]) 描述:同操作符?|,字符串数组$2里面是否存在的元素,在$1的顶层以key\elem\scalar的形式存在。 返回类型: 示例: 1
2
3
4
5 SELECT jsonb_exists_any('["1","2",3]', '{1, 2, 4}');
jsonb_exists_any
------------------
t
(1 row)
-
jsonb_concat(jsonb, jsonb) 描述:连接两个jsonb对象为一个jsonb。 返回类型:jsonb 示例: 1
2
3
4
5 SELECT jsonb_concat('{"a":1, "b":2}'::jsonb, '{"c":3, "d":4}'::jsonb);
jsonb_concat
----------------------------------
{"a": 1, "b": 2, "c": 3, "d": 4}
(1 row)
-
jsonb_set(target jsonb, path text[], new_value jsonb [, create_missing boolean]) 描述:返回target,用path指定的部分被new_value替换,或者如果create_missing为true(默认值为true)且path指定的项不存在,则添加new_value。与面向路径的运算符一样,path中出现的负整数从JSON数组的末尾开始计数。 返回类型:jsonb 示例: 1
2
3
4
5 SELECT jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0,f1}','[2,3,4]', false);
jsonb_set
---------------------------------------------
[{"f1": [2, 3, 4], "f2": null}, 2, null, 3]
(1 row)
-
jsonb_exists_all(jsonb, text[]) 描述:同操作符?&,字符串数组$2里面是否所有的元素,都在$1的顶层以key\elem\scalar的形式存在。 返回类型: bool 示例: 1
2
3
4
5 SELECT jsonb_exists_all('["1","2",3]', '{1, 2}');
jsonb_exists_all
------------------
t
(1 row)
-
jsonb_delete_array(jsonb, VARIADIC text[]) 描述:删除jsonb数组中的多个元素。 返回类型:jsonb 示例: 1
2
3
4
5 SELECT jsonb_delete_array('["a", "b", "c"]'::jsonb , 'a', 'b');
jsonb_delete_array
--------------------
["c"]
(1 row)
-
jsonb_delete_path(jsonb, text[]) 描述:删除jsonb数组中指定路径的元素。 返回类型:jsonb 示例: 1
2
3
4
5 SELECT jsonb_delete_path('{"a":{"b":{"c":1, "d":2}}, "e":3}'::jsonb , array['a', 'b']);
jsonb_delete_path
-------------------
{"a": {}, "e": 3}
(1 row)
-
jsonb_array_elements_text(array-jsonb) 描述:拆分数组,每一个元素返回一行。 返回类型:text 示例: 1
2
3
4
5
6
7
8 SELECT * FROM jsonb_array_elements_text('[1,true,[1,[2,3]],null]');
value
-------------
1
true
[1, [2, 3]]
(4 rows)
-
jsonb_each_text(object-jsonb) 描述:将对象的每个键值对拆分转换成一行两列。 返回类型:setof(key text, value text) 示例: 1
2
3
4
5
6
7 SELECT * FROM jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null}');
key | value
-----+-----------
f1 | [1, 2, 3]
f2 | {"f3": 1}
f4 |
(3 rows)
-
jsonb_populate_record_set(anyelement, array-jsonb [, bool]) 描述:参考上述函数json_populate_record、jsonb_populate_record,对$2数组的每一个元素进行上述参数函数的操作,因此这也要求$2数组的每个元素都是object-json类型。 返回类型:setof anyelement 示例: 1
2
3
4
5
6 SELECT * FROM json_populate_recordset(null::jpop, '[{"a":1,"b":2},{"a":3,"b":4}]');
a | b | c
---+---+---
1 | 2 |
3 | 4 |
(2 rows)
-
jsonb_array_elements(array-jsonb) 描述:拆分数组,每一个元素返回一行。 返回类型:jsonb 示例: 1
2
3
4
5
6
7
8 SELECT jsonb_array_elements('[1,true,[1,[2,3]],null]');
jsonb_array_elements
----------------------
1
true
[1, [2, 3]]
null
(4 rows)