当前位置:网站首页>金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(六))
金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(六))
2022-07-23 03:35:00 【沉舟侧畔千帆过_】
8.175. JSON_AGG
用法:
json_agg(expression)功能:
聚集函数,将传入值包括空值聚集成一个JSON数组。
例子:
SELECT json_agg(q) FROM ( SELECT $$a$$ || x AS b, y AS c, ARRAY[ROW(x.*,ARRAY[1,2,3]), ROW(y.*,ARRAY[4,5,6])] AS z FROM generate_series(1,2) x, generate_series(4,5) y) q;
8.176. JSON_ARRAY_ELEMENTS
用法:
json_array_elements(json)功能:
JSON处理函数,将传入值包括空值聚集成一个JSON数组。
例子:
SELECT json_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]');
8.177. JSON_ARRAY_ELEMENTS_TEXT
用法:
json_array_elements_text(json)功能:
JSON处理函数,把一个JSON数组扩展成
text值集合。例子:
SELECT * FROM json_array_elements_text('["foo","bar"]');
8.178. JSON_ARRAY_LENGTH
用法:
json_array_length(json)功能:
JSON处理函数,返回最外层JSON数组中的元素数量。
例子:
SELECT json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
8.179. JSON_BUILD_ARRAY
用法:
json_build_array( VARIADIC "any")功能:
JSON处理函数,将可变参数列表构造成一个可能包含不同数据类型的JSON数组。
例子:
SELECT json_build_array(1,2,'3',4,5);
8.180. JSON_BUILD_OBJECT
用法:
json_build_object( VARIADIC "any")功能:
JSON处理函数,将可变参数列表构造成一个JSON 对象,通过转换,该参数列表由交替出现的键和值构成。
例子:
SELECT json_build_object('foo',1,'bar',2);
8.181. JSON_EACH
用法:
json_each(json)功能:
JSON处理函数,扩展最外层的JSON对象成为一组键值对。
例子:
SELECT * FROM json_each('{"a":"foo", "b":"bar"}');
8.182. JSON_EACH_TEXT
用法:
json_each_text(json)功能:
JSON处理函数,扩展最外层的JSON对象成为一组键值对,返回值为
text类型。例子:
SELECT * FROM json_each_text('{"a":"foo",:"bar"}')`;
8.183. JSON_EXTRACT_PATH
用法:
json_extract_path(from_json json, VARIADIC path_elems text[])功能:
JSON处理函数,返回由
path_elems指向的JSON值(等效于#>操作符)。例子:
SELECT json_extract_path('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4');
8.184. JSON_EXTRACT_PATH_TEXT
用法:
json_extract_path(from_json json, VARIADIC path_elems text[])功能:
JSON处理函数,以
text类型返回由path_elems指向的JSON值(等效于#>操作符)。例子:
SELECT json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f 4', 'f6');
8.185. JSON_OBJECT
用法:
json_object(text[])功能:
JSON处理函数,从文本数组中构造JSON对象,该函数必须可以使具有偶数个成员的一维数组(成员被当做交替出现的键值对),或者是一个二维数组(每一个内部数组刚好有两个元素,可以被看做键值对) 。
例子:
SELECT json_object('{a, 1, b, "def", c, 3.5}'); SELECT json_object('{ {a,1},{b, "def"},{c, 3.5}}');
8.186. JSON_OBJECT_AGG
用法:
json_object_agg(name, value)功能:
聚集函数,将
name和value对聚合成JSON对象,值可以为空,名字不能为空。例子:
CREATE TEMP TABLE foo (serial_num int, name text, type text); INSERT INTO foo VALUES (847001,'t15','GE1043'); INSERT INTO foo VALUES (847002,'t16','GE1043'); INSERT INTO foo VALUES (847003,'sub-alpha','GESS90'); SELECT json_object_agg(name, type) FROM foo;
8.187. JSON_OBJECT_KEYS
用法:
json_object_keys(json)功能:
JSON函数,返回外层JSON对象中键的集合。
例子:
SELECT json_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}');
8.188. JSON_POPULATE_RECORD
用法:
json_populate_record(base anyelement,from_json json)功能:
JSON函数,扩展
from_json中的对象成一个行,它的列匹配由base定义的记录类型。例子:
SELECT * FROM json_populate_record(null::myrowtype,'{"a":1, "b": ["2", "a b"],"c": {"d":4, "e": "ab c"}}');
8.189. JSON_STRIP_NULLS
用法:
json_strip_nulls(from_json json)功能:
JSON函数,返回
from_json,其中所有具有空值的对象域都被过滤掉,其他空值不动。例子:
SELECT json_strip_nulls('[{"f1":1,"f2":null},2,null,3]');
8.190. JSON_TO_RECORD
用法:
json_to_record(json)功能:
JSON函数,从一个JSON对象构建一个任意的记录,正如所有返回
record的函数一样,调用者必须用一个AS子句显式的定义记录的结构。例子:
SELECT * FROM json_to_record('{"a":1,"b":[1,2,3],"c":[1,2,3],"e":"bar","r": {"a": 123, "b": "a b c"}}') as x(aint,b text, c int[], d text, r myrowtype);
8.191. JSON_TO_RECORDSET
用法:
json_to_recordset(json)功能:
JSON函数,从一个JSON对象数组构建一个任意的记录集合,正如所有返回
record的函数一样,调用者必须用一个AS子句显式的定义记录的结构。例子:
SELECT * FROM json_to_recordset ('[{"a":1,"b":"foo"},{"a":"2","c":"bar"}]')as x(a int, b text);
8.192. JSON_TYPEOF
用法:
json_typeof(json)功能:
JSON函数,把最外层的JSON对象类型作为一个文本串返回。可能类型是:
object、array、string、number、boolean以及null。例子:
SELECT json_typeof('-123.4');
8.193. JSONB_AGG
用法:
jsonb_agg(expression)功能:
聚集函数,将传入值包括空值聚集成一个JSON数组。
例子:
SELECT jsonb_agg(q) FROM ( SELECT $$a$$ || x AS b, y AS c, ARRAY[ROW(x.*,ARRAY[1,2,3]), ROW(y.*,ARRAY[4,5,6])] AS z FROM generate_series(1,2) x, generate_series(4,5) y) q;
8.194. JSONB_ARRAY_ELEMENTS
用法:
jsonb_array_elements(jsonb)功能:
JSON处理函数,将传入值包括空值聚集成一个JSON数组。
例子:
SELECT jsonb_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]');
8.195. JSONB_ARRAY_ELEMENTS_TEXT
用法:
jsonb_array_elements_text(jsonb)功能:
JSON处理函数,把一个JSON数组扩展成
text值集合。例子:
SELECT * FROM jsonb_array_elements_text('["foo","bar"]');
8.196. JSONB_ARRAY_LENGTH
用法:
jsonb_array_length(jsonb)功能:
JSON处理函数,返回最外层JSON数组中的元素数量。
例子:
SELECT jsonb_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
8.197. JSONB_BUILD_ARRAY
用法:
jsonb_build_array( VARIADIC "any")功能:
JSON处理函数,将可变参数列表构造成一个可能包含不同数据类型的JSON数组。
例子:
SELECT jsonb_build_array(1,2,'3',4,5);
8.198. JSONB_BUILD_OBJECT
用法:
jsonb_build_object( VARIADIC "any")功能:
JSON处理函数,将可变参数列表构造成一个JSON 对象,通过转换,该参数列表由交替出现的键和值构成。
例子:
SELECT jsonb_build_object('foo',1,'bar',2);
8.199. JSONB_EACH
用法:
jsonb_each(jsonb)功能:
JSON处理函数,扩展最外层的JSON对象成为一组键值对。
例子:
SELECT * FROM jsonb_each('{"a":"foo", "b":"bar"}');
8.200. JSONB_EACH_TEXT
用法:
jsonb_each_text(jsonb)功能:
JSON处理函数,扩展最外层的JSON对象成为一组键值对,返回值为
text类型。例子:
SELECT * FROM jsonb_each_text('{"a":"foo",:"bar"}')`;
8.201. JSONB_EXTRACT_PATH
用法:
jsonb_extract_path(from_json jsonb, VARIADIC path_elems text[])功能:
JSON处理函数,返回由
path_elems指向的JSON值(等效于#>操作符)。例子:
SELECT jsonb_extract_path('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4');
8.202. JSONB_EXTRACT_PATH_TEXT
用法:
jsonb_extract_path(from_json jsonb, VARIADIC path_elems text[])功能:
JSON处理函数,以
text类型返回由path_elems指向的JSON值(等效于#>操作符)。例子:
SELECT jsonb_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f 4', 'f6');
8.203. JSONB_INSERT
用法:
jsonb_insert(target jsonb, path text[], new_value jsonb [, insert_after boolean])功能:
JSON处理函数,返回被插入了
new_value的target。如果path指定的target节在一个JSONB数组中,new_value将被插入到目标之前(insert_after默认为false)或者之后(insert_after为true)。 如果path指定的target节在一个JSONB对象内,则只有当target不存在时才插入new_value。 对于面向路径的操作符来说,出现在path中的负整数表示从JSONB数组的末尾开始计数。例子:
SELECT jsonb_insert('{"a": [0,1,2]}', '{a,1}', '"new_value"'); SELECT jsonb_insert('{"a":[0,1,2]}','{a, 1}','"new_value"', true);
8.204. JSONB_OBJECT
用法:
jsonb_object(text[])功能:
JSON处理函数,从文本数组中构造JSON对象,该函数必须可以使具有偶数个成员的一维数组(成员被当做交替出现的键值对),或者是一个二维数组(每一个内部数组刚好有两个元素,可以被看做键值对) 。
例子:
SELECT jsonb_object('{a, 1, b, "def", c, 3.5}'); SELECT jsonb_object('{ {a,1},{b, "def"},{c, 3.5}}');
8.205. JSONB_OBJECT_AGG
用法:
jsonb_object_agg(name, value)功能:
聚集函数,将
name和value对聚合成JSON对象,值可以为空,名字不能为空。例子:
CREATE TEMP TABLE foo (serial_num int, name text, type text); INSERT INTO foo VALUES (847001,'t15','GE1043'); INSERT INTO foo VALUES (847002,'t16','GE1043'); INSERT INTO foo VALUES (847003,'sub-alpha','GESS90'); SELECT jsonb_object_agg(name, type) FROM foo;
8.206. JSONB_OBJECT_KEYS
用法:
jsonb_object_keys(jsonb)功能:
JSON函数,返回外层JSON对象中键的集合。
例子:
SELECT jsonb_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}');
8.207. JSONB_PATH_EXISTS
用法:
jsonb_path_exists(target jsonb, path jsonpath[, vars jsonb [, silent bool]])功能:
JSON函数,检查JSON路径是否返回指定JSON值的任何项。
例子:
SELECT jsonb_path_exists('{"a":[1,2,3,4,5]}', '$.a[*] ?(@ >= $min && @ <= $max)', '{"min":2,"max":4}');
8.208. JSONB_PATH_MATCH
用法:
jsonb_path_match(target jsonb, path jsonpath [, vars jsonb [, silent bool]])功能:
JSON函数,返回指定JSON值的JSON路径谓词检查的结果。只考虑结果的第一项。如果结果不是布尔值,则返回NULL.
例子:
SELECT jsonb_path_match('{"a":[1,2,3,4,5]}', 'exists($.a[*] ? (@ >= $min && @ <= $max))', '{"min":2,"max":4}');
8.209. JSONB_PATH_QUERY
用法:
jsonb_path_query(targetjsonb, path jsonpath [, vars jsonb [, silent bool]])功能:
JSON函数,获取指定JSON值的JSON路径返回的所有项.
例子:
SELECT * FROM jsonb_path_query('{"a":[1,2,3,4,5]}', '$.a[*] ? (@ >= $min && @ <= $max)', '{"min":2,"max":4}');
8.210. JSONB_PATH_QUERY_ARRAY
用法:
jsonb_path_query_array(target jsonb, path jsonpath[, vars jsonb [, silent bool]])功能:
JSON函数,获取指定JSON值的JSON路径返回的所有项,并将结果包装到数组中。
例子:
SELECT * FROM jsonb_path_query_array('{"a":[1,2,3,4,5]}', '$.a[*] ? (@ >= $min && @ <= $max)', '{"min":2,"max":4}');
8.211. JSONB_PATH_QUERY_FIRST
用法:
jsonb_path_query_first(targetjsonb, path jsonpath [, vars jsonb [, silent bool]])功能:
JSON函数,获取指定JSON值的JSON路径返回的第一个JSON项。在没有结果时返回NULL。
例子:
SELECT * FROM jsonb_path_query_first('{"a":[1,2,3,4,5]}', '$.a[*] ? (@ >= $min && @ <= $max)', '{"min":2,"max":4}');
8.212. JSONB_POPULATE_RECORD
用法:
jsonb_populate_record(base anyelement,from_json jsonb)功能:
JSON函数,扩展
from_json中的对象成一个行,它的列匹配由base定义的记录类型。例子:
SELECT * FROM jsonb_populate_record(null::myrowtype,'{"a":1, "b": ["2", "a b"],"c": {"d":4, "e": "ab c"}}');
8.213. JSONB_POPULATE_RECORDSET
用法:
jsonb_populate_recordset(base anyelement,from_json jsonb)功能:
JSON函数,扩展
from_json中最外层的对象数组成一个集合,它的列匹配由base定义的记录类型。例子:
SELECT json_populate_recordset(row(1,2), '[]');
8.214. JSONB_PRETTY
用法:
jsonb_pretty(from_json jsonb)功能:
JSON函数,把
from_json处理成一段带缩进的JSON文本。例子:
SELECT jsonb_pretty('[{"f1":1,"f2":null},2,null,3]');
8.215. JSONB_SET
用法:
jsonb_set(target jsonb, path text[],new_value jsonb[, create_missing boolean])功能:
JSON函数,返回
target其中由path指定的节用new_value替换,如果指定的项不存在并且create_missing为真(默认为真)则加上new_value。 正如面向路径的操作符一样,出现在path中的负整数表示从JSON数组的末尾开始数例子:
SELECT jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0,f1}', '[2,3,4]', false);
8.216. JSONB_STRIP_NULLS
用法:
jsonb_strip_nulls(from_json jsonb)功能:
JSON函数,返回
from_json,其中所有具有空值的对象域都被过滤掉,其他空值不动。例子:
SELECT jsonb_strip_nulls('[{"f1":1,"f2":null},2,null,3]');
8.217. JSONB_TO_RECORD
用法:
jsonb_to_record(jsonb)功能:
JSON函数,从一个JSON对象构建一个任意的记录,正如所有返回
record的函数一样,调用者必须用一个AS子句显式的定义记录的结构。例子:
SELECT * FROM jsonb_to_record('{"a":1,"b":[1,2,3],"c":[1,2,3],"e":"bar","r": {"a": 123, "b": "a b c"}}') as x(aint,b text, c int[], d text, r myrowtype);
8.218. JSONB_TO_RECORDSET
用法:
jsonb_to_recordset(json)功能:
JSON函数,从一个JSON对象数组构建一个任意的记录集合,正如所有返回
record的函数一样,调用者必须用一个AS子句显式的定义记录的结构。例子:
SELECT * FROM jsonb_to_recordset ('[{"a":1,"b":"foo"},{"a":"2","c":"bar"}]')as x(a int, b text);
8.219. JSONB_TYPEOF
用法:
jsonb_typeof(json)功能:
JSON函数,把最外层的JSON对象类型作为一个文本串返回。可能类型是:
object、array、string、number、boolean以及null。例子:
SELECT jsonb_typeof('-123.4');
8.220. JUSTIFY_DAYS
用法:
justify_days(interval)功能:
时间函数,调整间隔,使30天时间段表示为月 。
例子:
SELECT justify_days(interval '35 days');
8.221. JUSTIFY_HOURS
用法:
justify_hours(interval)功能:
时间函数,调整间隔,使24小时时间段表示为日 。
例子:
SELECT justify_hours(interval '27 hours');
8.222. JUSTIFY_INTERVAL
用法:
justify_interval(interval)功能:
时间函数,使用
justify_days和justify_hours调整间隔,并进行额外的符号调整。例子:
SELECT justify_interval(interval '1 month -1 hour') as "1 month -1 hour";
8.223. LAG
用法:
lag(value anyelement[, offset integer [,default anyelement ]])功能:
返回value,它在分区内当前行的之前offset个位置的行上计算;如果没有这样的行,返回default替代(必须和value类型相同)。offset和default都是根据当前行计算的结果。如果忽略它们,则offset默认是1,default默认是空值。
例子:
CREATE TABLE test(id integer); INSERT INTO test values(1); INSERT INTO test values(3); INSERT INTO test values(6); SELECT id, lag(id, 1, 0) from test;
边栏推荐
- Visual full link log tracking
- 九张图纵观加密市场周期规律
- error MSB4181: “QtRunWork”任务返回了 false,但未记录错误
- Android development learning diary - content provider (cross application database modification)
- 利用反射对修饰符为final的成员变量进行修改
- Args parameter parsing
- moment 获取周、月、季、年
- 宇视NVR设备接入EasyCVR平台,离线后无法上线该如何解决?
- 图文并茂演示小程序movable-view的可移动范围
- Three goals and eight tasks of intelligent construction pilot city notice
猜你喜欢

【Azure 事件中心】Azure Event Hub 新功能尝试 -- 异地灾难恢复 (Geo-Disaster Recovery)

This tool complements the last kilometer of JMeter performance analysis

Use modern development methods and thinking to get rid of the "stumbling block" of legacy systems

Decompile the jar package / class file / modify the jar package using the decompile plug-in of idea

three文档使用

60 open-ended test questions, recite them and get a pay rise directly

"Lost wake up problem" in multithreading | why do wait() and notify() need to be used with the synchronized keyword?

141.环形链表

C语言文件操作

什么是Per-Title编码?
随机推荐
Is it safe for Huatai Securities to open an account online? Is it true
[C language foundation] 16 variable array (array length can be extended)
华泰证劵开户有骗局吗安全吗
Target detection XML file to achieve mixup data enhancement (modifying the file path can be used directly, which is very convenient)
Comprehensive summary of software quality management practice
How to add an operator in ONEFLOW
多线程中的「lost wake up 问题」| 为什么wait()和notify()需要搭配synchonized关键字使用?
redis分片集群如何搭建与使用
Anaconda 换源以及安装opencv
c# 字节数组和类相互转换
2.判断语句
These four key technologies are necessary to realize the unified management of urban governance through one network
This tool complements the last kilometer of JMeter performance analysis
Sum of three numbers: (sort + double pointer + pruning)
Airtest脚本的点击位置与点击偏移
Network communication principle and IP address allocation principle. The seven layers of the network are physical layer, data link layer, network layer, transmission layer, session layer, presentation
三数之和:(排序+双指针+剪枝)
SSM framework takeout ordering system
【VSCODE】当前工作目录非当前文件夹/pathlib打印cwd路径错误
这个工具,补齐了 JMeter性能分析最后一公里短板