内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

怎么使用PostgreSQL的SQL/JSON函數(shù)

這篇文章主要講解了“怎么使用PostgreSQL的SQL/JSON函數(shù)”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么使用PostgreSQL的SQL/JSON函數(shù)”吧!

創(chuàng)新互聯(lián)公司主營比如網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā),比如h5微信平臺小程序開發(fā)搭建,比如網(wǎng)站營銷推廣歡迎比如等地區(qū)企業(yè)咨詢

PostgreSQL 12提供了SQL/JSON函數(shù)用以兼容SQL 2016 SQL/JSON特性.
這些函數(shù)包括:

[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或以下版本,則需要使用#>>等操作符實現(xiàn)

testdb=# select data#>>'{equipment,rings,0,name}' AS ring_name FROM characters;
    ring_name    
-----------------
 ring of despair
(1 row)

感謝各位的閱讀,以上就是“怎么使用PostgreSQL的SQL/JSON函數(shù)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么使用PostgreSQL的SQL/JSON函數(shù)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

網(wǎng)頁標(biāo)題:怎么使用PostgreSQL的SQL/JSON函數(shù)
URL鏈接:http://www.rwnh.cn/article44/jdcphe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)搜索引擎優(yōu)化、App開發(fā)、網(wǎng)站設(shè)計全網(wǎng)營銷推廣、品牌網(wǎng)站設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司
南安市| 洮南市| 越西县| 拉孜县| 钦州市| 沾益县| 阳西县| 金乡县| 普陀区| 莱州市| 庆安县| 镇雄县| 襄樊市| 嘉兴市| 石棉县| 宁城县| 康马县| 肥乡县| 巴彦县| 金乡县| 颍上县| 卫辉市| 略阳县| 沂水县| 嵩明县| 乌审旗| 靖安县| 佛山市| 平湖市| 广南县| 岚皋县| 盐亭县| 黄陵县| 云阳县| 河池市| 寿光市| 凯里市| 昌乐县| 榆社县| 米泉市| 自治县|