婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 如何獲取PostgreSQL數據庫中的JSON值

如何獲取PostgreSQL數據庫中的JSON值

熱門標簽:濟南外呼網絡電話線路 400電話申請客服 移動外呼系統模擬題 地圖標注要花多少錢 電銷機器人能補救房產中介嗎 天津開發區地圖標注app 電話機器人怎么換人工座席 江蘇400電話辦理官方 廣州電銷機器人公司招聘

在PostgreSQL數據庫中有一列為JSON,要獲取JSON中得數據可以用下面sql:

select orderno as OrderNo
 ,amount as Amount
 ,ordertime as OrderTime
 , recordtype as RecordType
from jsonb_to_recordset(( --特定方法
  select array_to_json(array_agg(data)) --轉換成一個數組
  from wallet_details
  where id = @id
  )::jsonb) as x(orderno text, amount numeric(16, 6), ordertime text, recordtype varchar(32));

如果你獲取得數據是當前行,但是JSON中也要取出來幾個值可以用下面的方式獲取:

select pay_params::json->>'Key' as Md5Key ,
  pay_params::json->>'AppId' as Appid ,
  pay_params::json->>'MchId' as Mchid ,
  pay_params::json->>'SubMchId' as Submchid ,
  tenant_id as Tenant_Id
  from spm_wallet_settings where id='12'

補充:PostgreSql數據庫sql語句取Json值

1:json字段實例:

{
“boxNum”: 0,
“orderNum”: 0,
“commentNum”: 0
}

A.取boxNum的值

1.1)select 字段名->‘boxNum' from 表名;

1.2)select jsonb_extract_path_text字段名, ‘boxNum') from 表名;

2:json字段實例:

{
“boxNum”: “0”,
“orderNum”: “0”,
“commentNum”: “0”
}

A.取boxNum的值,不帶雙引號。

2.1)select 字段名->>‘boxNum' from 表名;

2.2)select jsonb_extract_path_text字段名, ‘boxNum') from 表名;

3:json字段實例:

{
“unitPrices”: [{
“price”: 10.0,
“unitId”: “8”,
“unitName”: “500克”,
“unitAmount”: “0”,
“isPMDefault”: true,
“isHomeDefault”: true,
“originalPrice”: 10.0
}],
“productName”: “遠洋 加拿大 螯龍蝦 野生捕撈”,
“productType”: 1,
“skuPortRate”: {
“id”: “a6b83048-3878-4698-88c2-2a9de288ac56”,
“cityId”: “2bf8c60c-789d-433a-91ae-8e4ae3e587a4”,
“dynamicProperties”: [{
“name”: “死亡率”,
“propertiesId”: “f05bda8c-f27c-4cc6-b97e-d4bd07272c81”,
“propertieValue”: {
“value”: “2.0”
}
}, {
“name”: “失水率”,
“propertiesId”: “ee9d95d7-7e28-4d54-b572-48ae64146c46”,
“propertieValue”: {
“value”: “3.0”
}
}]
},
“quotePriceAttribute”: {
“currencyName”: “人民幣”
}
}

A.取quotePriceAttribute中的currencyName幣制名稱

select (字段名>>‘quotePriceAttribute')::json->>‘currencyName' from 表名;

B.取unitPrices中的price單價

select jsonb_array_elements((字段名->>‘unitPrices')::jsonb)->>‘price' from 表名;

C.取skuPortRate中的dynamicProperties的name為死亡率的propertieValue里面的value;

select bb->‘propertieValue'->>‘value' as value from (
select jsonb_array_elements(((字段名->>‘skuPortRate')::json->>‘dynamicProperties')::jsonb) as bb from 表名) as dd where dd.bb @> ‘{“name”: “死亡率”}';

4.json字段實例:

[{“name”: “捕撈方式”, “showType”: 4, “propertiesId”: “9a14e435-9688-4e9b-b254-0e8e7cee5a65”,
“propertieValue”: {“value”: “野生捕撈”, “enValue”: “Wild”}},
{“name”: “加工方式”, “showType”: 4, “propertiesId”: “7dc101df-d262-4a75-bdca-9ef3155b7507”,
“propertieValue”: {“value”: “單凍”, “enValue”: “Individual Quick Freezing”}},
{“name”: “原產地”, “showType”: 4, “propertiesId”: “dc2b506e-6620-4e83-8ca1-a49fa5c5077a”,
“propertieValue”: {“value”: “愛爾蘭”, “remark”: “”, “enValue”: “Ireland”}}]

–獲取原產地

select
(SELECT ss->‘propertieValue' as mm FROM
(SELECT jsonb_array_elements (dynamic_properties) AS ss FROM product
where id=a.id) as dd where dd.ss @> ‘{“name”: “原產地”}')->>‘value' as cuntry,
a.*
from product as a where a.id=‘633dd80f-7250-465f-8982-7a7f01aaeeec';

5:json例子:huren:[“aaa”,“bbb”,“ccc”…]

需求:取值aaa去““雙引號”

select replace(cast(jsonb_array_elements(huren) as text), ‘"','') from XXX limit 1

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • postgreSQL數據庫默認用戶postgres常用命令分享
  • postgresql修改完端口后直接psql連接數據庫報錯的解決
  • postgresql數據庫安裝部署搭建主從節點的詳細過程(業務庫)
  • postgreSQL數據庫的監控及數據維護操作
  • PostgreSQL數據庫中匿名塊的寫法實例
  • SpringBoot連接使用PostgreSql數據庫的方法
  • PostgreSql 導入導出sql文件格式的表數據實例
  • PostgreSQL upsert(插入更新)數據的操作詳解
  • 使用postgresql 模擬批量數據插入的案例

標簽:昭通 海西 榆林 溫州 濮陽 寶雞 辛集 杭州

巨人網絡通訊聲明:本文標題《如何獲取PostgreSQL數據庫中的JSON值》,本文關鍵詞  如何,獲取,PostgreSQL,數據庫,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《如何獲取PostgreSQL數據庫中的JSON值》相關的同類信息!
  • 本頁收集關于如何獲取PostgreSQL數據庫中的JSON值的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 海南省| 贵阳市| 报价| 洛浦县| 衡山县| 寻甸| 呼图壁县| 红河县| 黄平县| 辽源市| 大荔县| 远安县| 柳河县| 玉门市| 汝阳县| 肃宁县| 博白县| 清远市| 平塘县| 同心县| 伊春市| 涟源市| 无锡市| 河津市| 普安县| 梁平县| 丹江口市| 东乡族自治县| 金山区| 青川县| 许昌市| 乌拉特后旗| 普兰县| 衡阳市| 雷山县| 清镇市| 丽江市| 黔西县| 同心县| 务川| 沽源县|