久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

怎么使用PostgreSQL的SQL/JSON函數

162次閱讀
沒有評論

共計 2933 個字符,預計需要花費 8 分鐘才能閱讀完成。

這篇文章主要講解了“怎么使用 PostgreSQL 的 SQL/JSON 函數”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“怎么使用 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 TABLE
Time: 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.1
pg12@testdb # },
pg12@testdb # { name  :  ring of strength ,
pg12@testdb #  weight  : 2.4
pg12@testdb # }
pg12@testdb # ],
pg12@testdb #  arm_right  :  Sword of flame ,
pg12@testdb #  arm_left  :  Shield of faith 
pg12@testdb # }
pg12@testdb # } 
INSERT 0 1
Time: 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 函數這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-26發表,共計2933字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 肇州县| 黄山市| 高邑县| 临猗县| 天镇县| 安庆市| 简阳市| 保康县| 莆田市| 柏乡县| 尖扎县| 许昌县| 察雅县| 东至县| 佛学| 万源市| 苍南县| 景洪市| 六安市| 青河县| 扎兰屯市| 八宿县| 丹凤县| 东山县| 墨脱县| 鸡泽县| 扎兰屯市| 安远县| 广饶县| 岱山县| 石台县| 崇明县| 阿拉善左旗| 安达市| 深水埗区| 武强县| 民勤县| 皋兰县| 偃师市| 大兴区| 麟游县|