怎么使用PostgreSQL的SQL/JSON函数
发表于:2025-02-23 作者:千家信息网编辑
千家信息网最后更新 2025年02月23日,这篇文章主要讲解了"怎么使用PostgreSQL的SQL/JSON函数",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"怎么使用PostgreSQL的SQ
千家信息网最后更新 2025年02月23日怎么使用PostgreSQL的SQL/JSON函数
这篇文章主要讲解了"怎么使用PostgreSQL的SQL/JSON函数",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"怎么使用PostgreSQL的SQL/JSON函数"吧!
PostgreSQL 12提供了SQL/JSON函数用以兼容SQL 2016 SQL/JSON特性.
这些函数包括:
[local]:5432 pg12@testdb=# \df jsonb_path* List of functions Schema | Name | Result data type | Argument data types | Type ------------+------------------------+------------------+-------------------------------------------------------------------------------------------+------ pg_catalog | jsonb_path_exists | boolean | target jsonb, path jsonpath, vars jsonb DEFAULT '{}'::jsonb, silent boolean DEFAULT false | func pg_catalog | jsonb_path_exists_opr | boolean | jsonb, jsonpath | func pg_catalog | jsonb_path_match | boolean | target jsonb, path jsonpath, vars jsonb DEFAULT '{}'::jsonb, silent boolean DEFAULT false | func pg_catalog | jsonb_path_match_opr | boolean | jsonb, jsonpath | func pg_catalog | jsonb_path_query | SETOF jsonb | target jsonb, path jsonpath, vars jsonb DEFAULT '{}'::jsonb, silent boolean DEFAULT false | func pg_catalog | jsonb_path_query_array | jsonb | target jsonb, path jsonpath, vars jsonb DEFAULT '{}'::jsonb, silent boolean DEFAULT false | func pg_catalog | jsonb_path_query_first | jsonb | target jsonb, path jsonpath, vars jsonb DEFAULT '{}'::jsonb, silent boolean DEFAULT false | func(7 rows)
简单试用:
[local]:5432 pg12@testdb=# CREATE TABLE characters (data jsonb); "weight" : 0.1 }, {"name" : "ring of strength", "weight" : 2.4 } ], "arm_right" : "Sword of flame", "arm_left" : "Shield of faith" }}');CREATE TABLETime: 208.690 ms[local]:5432 pg12@testdb=# INSERT INTO characters VALUES ('pg12@testdb'# { "name" : "Yksdargortso",pg12@testdb'# "id" : 1,pg12@testdb'# "sex" : "male",pg12@testdb'# "hp" : 300,pg12@testdb'# "level" : 10,pg12@testdb'# "class" : "warrior",pg12@testdb'# "equipment" :pg12@testdb'# {pg12@testdb'# "rings" : [pg12@testdb'# { "name" : "ring of despair",pg12@testdb'# "weight" : 0.1pg12@testdb'# },pg12@testdb'# {"name" : "ring of strength",pg12@testdb'# "weight" : 2.4pg12@testdb'# }pg12@testdb'# ],pg12@testdb'# "arm_right" : "Sword of flame",pg12@testdb'# "arm_left" : "Shield of faith"pg12@testdb'# }pg12@testdb'# }');INSERT 0 1Time: 3.881 ms[local]:5432 pg12@testdb=# [local]:5432 pg12@testdb=# [local]:5432 pg12@testdb=# SELECT jsonb_path_query(data, '$.equipment.rings[0].name') AS ring_name FROM characters; ring_name ------------------- "ring of despair"(1 row)Time: 10.081 ms[local]:5432 pg12@testdb=# SELECT jsonb_path_query(data, '$.equipment.rings[0].*') AS data FROM characters; data ------------------- "ring of despair" 0.1(2 rows)Time: 0.687 ms[local]:5432 pg12@testdb=# SELECT jsonb_path_query(data, '$.equipment.rings[*].weight.floor()') AS weight FROM characters; weight -------- 0 2(2 rows)
如果是PG 11或以下版本,则需要使用#>>等操作符实现
testdb=# select data#>>'{equipment,rings,0,name}' AS ring_name FROM characters; ring_name ----------------- ring of despair(1 row)
感谢各位的阅读,以上就是"怎么使用PostgreSQL的SQL/JSON函数"的内容了,经过本文的学习后,相信大家对怎么使用PostgreSQL的SQL/JSON函数这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
函数
学习
内容
就是
思路
情况
操作符
文章
更多
版本
特性
用以
知识
知识点
篇文章
跟着
问题
实践
推送
研究
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
崩溃大陆在线服务器怎么进
机器人需要软件开发吗
网络技术开发公司净利润怎么样
实训网络安全课总结报告
在软件开发中 ()不能用来
广州软件开发框架
思维中国网络技术有限公司
特殊办公室网络安全有哪方面
平湖软件开发哪家靠谱
cs架构数据库安全问题
西藏加油卡 网络安全
云顶之弈哪个服务器水平高
软件开发参考文献大全
软件开发自学步骤视频教程
lol英雄服务器
服务器怎么解除安全模式
软件开发后期是什么
软件开发 画图工具
网络安全与法律基础
维护网络安全心得体会800
打开本地电影服务器运行失败
游戏中使用数据库
华为原神无法连接服务器
如何加强我国网络安全建设
服务器可以不用raid卡吗
软件开发未来一年的规划
控制系统网络安全系统
常德棋牌软件开发公司有哪些
网络安全技巧教学
现在吃鸡不可以选择服务器了么